Dynomotion

Group: DynoMotion Message: 3435 From: himykabibble Date: 1/25/2012
Subject: Houston, We Have A (Bizarre) Problem...
So, I've been exercising my app on the machine, and for the most parts, things are working OK, though it seems a bit "sluggish" to me. For example, when I single-step, it takes a good 1/2 second or more to execute a line of G-code containing nothing more than a single comment. When running, the DROs update in significant increments, rather than the relatively smooth updates I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I would expect it to appear smoother. Could still be problems in my code, so none of this concerns me at all at this early stage of the game.

However, in working on the problem of the mis-executing DSP threads, I've discovered something really odd. I tested the two programs in question under KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they both execute correctly first time, every time, without fail. But, run them under my app, using the few lines of code posted last night, and the threads start, may, or may not, make the first move, then go out to lunch. KMotion confirms the threads remain running long after they should have terminated, so they seem to be stuck waiting for..... something. Now, here's the bizarre part - If I open KMotionCNC - I don't do anything else, just open the app - the thread immediately picks up and runs to completion correctly! If I just leave KMotionCNC running alongside my app, both DSP programs work perfectly every time. In addition, one of them uses a MsgBox to give a message to the user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does not appear UNTIL KMotionCNC get focus, even though the DSP thread was launched from MY app!

What is going on here? What is KMotionCNC doing that affects my DSP programs in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did NOT launch the threads? Is there some buffer or FIFO somewhere that's filling up and blocking communications? I'm at a total loss here...

Regards,
Ray L.
Group: DynoMotion Message: 3436 From: Tom Kerekes Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
Well I can explain part of it.  All the KFLOP -> PC App functionality has to be handled by your application.  KMotionCNC has code where after every MainStatus update KMotionCNC checks if it uploaded a command such as CycleStart, or Display a message box, or whatever.
 
See the function ServiceKFLOPCommands in KMotionCNCDlg.cpp
 
Regards
TK 
 

Group: DynoMotion Message: 3438 From: Brad Murry Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Ray,

 

I would ditch the timer as well, using a service thread to interact with the kflop will be much smoother.

 

Instead of running your updates via your timer’s callback you can either use the BackgroundWorker or an Async Delegate or parallel task if using .net4.0

 

 

 

Parallel tasks are best because the will automagically load your cpu usage based on how many cores are available, etc…

 

 

Background workers are pretty easy to use and have a comprehensive use model.

 

 

Async delegates(using beginInvoke(IAsyncCallback, object) are easy to use to and easy to read.

 

 

Whichever method you use, you will need to Invoke/Dispatch your control updates when using Winforms/WPF respectively.

 

 

It looks like you are using winforms, so here is a quick pseudo-example where I am using a common method that takes an Action as a parameter and decides whether to invoke or not::

 

        public void UpdateDocument(Action action)

        {

            if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is coming from a thread other than the GUI

            {

                _GuiHost.Parent.Invoke(action);//Merge action into the GUI thread

            }

            else

            {

                action();//Came from the same thread as the GUI, so no invocation required

            }

       }

 

 

In the updating method of whichever threading model you chose, you can use the above method like so::

 

 

 

   UpdateDocument(new Action(delegate()

   {

//Put your control updating code here…

//Example:

lblXaxisDest.Text = _AxisContainer[“X”].ActualPosition.ToString();

    }));

 

 

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Wednesday, January 25, 2012 3:42 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...

 

 

So, I've been exercising my app on the machine, and for the most parts, things are working OK, though it seems a bit "sluggish" to me. For example, when I single-step, it takes a good 1/2 second or more to execute a line of G-code containing nothing more than a single comment. When running, the DROs update in significant increments, rather than the relatively smooth updates I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I would expect it to appear smoother. Could still be problems in my code, so none of this concerns me at all at this early stage of the game.

However, in working on the problem of the mis-executing DSP threads, I've discovered something really odd. I tested the two programs in question under KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they both execute correctly first time, every time, without fail. But, run them under my app, using the few lines of code posted last night, and the threads start, may, or may not, make the first move, then go out to lunch. KMotion confirms the threads remain running long after they should have terminated, so they seem to be stuck waiting for..... something. Now, here's the bizarre part - If I open KMotionCNC - I don't do anything else, just open the app - the thread immediately picks up and runs to completion correctly! If I just leave KMotionCNC running alongside my app, both DSP programs work perfectly every time. In addition, one of them uses a MsgBox to give a message to the user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does not appear UNTIL KMotionCNC get focus, even though the DSP thread was launched from MY app!

What is going on here? What is KMotionCNC doing that affects my DSP programs in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did NOT launch the threads? Is there some buffer or FIFO somewhere that's filling up and blocking communications? I'm at a total loss here...

Regards,
Ray L.

Group: DynoMotion Message: 3439 From: himykabibble Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

OK, I understood maybe half of that.... I understand the concept of parallel tasks, and I think I see how to launch them, but it's less clear what makes sense to parallelize, and what is SAFE to parallelize.

Right now, I have a single display update loop, running 10X/second. It would be trivial to put that into a parallel task. I would like to have a single task doing nothing but monitoring and managing the KFLop connection state. But, I assume there can be only one thread interacting with the KFLop on behalf of the entire app, right? So it's not clear exactly how you're suggesting I re-factor this. What would you put where?

BTW - I'm also seeing some odd behavior on connection. It's fairly easy to get things into a persistent state where Connected returns true, but CheckIsReady() return false. The only solution is a disconnect and reconnect. Even that often will not do it, and it becomes necessary to kill the app entirely. So it appears something in dotNet is definitely getting into a bad state.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Ray,
>
>
>
> I would ditch the timer as well, using a service thread to interact with the
> kflop will be much smoother.
>
>
>
> Instead of running your updates via your timer's callback you can either use
> the BackgroundWorker or an Async Delegate or parallel task if using .net4.0
>
>
>
>
>
>
>
> Parallel tasks are best because the will automagically load your cpu usage
> based on how many cores are available, etc.
>
>
>
>
>
> Background workers are pretty easy to use and have a comprehensive use
> model.
>
>
>
>
>
> Async delegates(using beginInvoke(IAsyncCallback, object) are easy to use to
> and easy to read.
>
>
>
>
>
> Whichever method you use, you will need to Invoke/Dispatch your control
> updates when using Winforms/WPF respectively.
>
>
>
>
>
> It looks like you are using winforms, so here is a quick pseudo-example
> where I am using a common method that takes an Action as a parameter and
> decides whether to invoke or not::
>
>
>
> public void UpdateDocument(Action action)
>
> {
>
> if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> coming from a thread other than the GUI
>
> {
>
> _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> thread
>
> }
>
> else
>
> {
>
> action();//Came from the same thread as the GUI, so no
> invocation required
>
> }
>
> }
>
>
>
>
>
> In the updating method of whichever threading model you chose, you can use
> the above method like so::
>
>
>
>
>
>
>
> UpdateDocument(new Action(delegate()
>
> {
>
> //Put your control updating code here.
>
> //Example:
>
> lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
>
> }));
>
>
>
>
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 3:42 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> So, I've been exercising my app on the machine, and for the most parts,
> things are working OK, though it seems a bit "sluggish" to me. For example,
> when I single-step, it takes a good 1/2 second or more to execute a line of
> G-code containing nothing more than a single comment. When running, the DROs
> update in significant increments, rather than the relatively smooth updates
> I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I
> would expect it to appear smoother. Could still be problems in my code, so
> none of this concerns me at all at this early stage of the game.
>
> However, in working on the problem of the mis-executing DSP threads, I've
> discovered something really odd. I tested the two programs in question under
> KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they
> both execute correctly first time, every time, without fail. But, run them
> under my app, using the few lines of code posted last night, and the threads
> start, may, or may not, make the first move, then go out to lunch. KMotion
> confirms the threads remain running long after they should have terminated,
> so they seem to be stuck waiting for..... something. Now, here's the bizarre
> part - If I open KMotionCNC - I don't do anything else, just open the app -
> the thread immediately picks up and runs to completion correctly! If I just
> leave KMotionCNC running alongside my app, both DSP programs work perfectly
> every time. In addition, one of them uses a MsgBox to give a message to the
> user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does
> not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> launched from MY app!
>
> What is going on here? What is KMotionCNC doing that affects my DSP programs
> in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did
> NOT launch the threads? Is there some buffer or FIFO somewhere that's
> filling up and blocking communications? I'm at a total loss here...
>
> Regards,
> Ray L.
>
Group: DynoMotion Message: 3441 From: himykabibble Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Gary,

I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume that could be used to push GUI updates from my KM "gasket" when something changes, rather than pulling them from the main app, right?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Ray,
>
>
>
> I would ditch the timer as well, using a service thread to interact with the
> kflop will be much smoother.
>
>
>
> Instead of running your updates via your timer's callback you can either use
> the BackgroundWorker or an Async Delegate or parallel task if using .net4.0
>
>
>
>
>
>
>
> Parallel tasks are best because the will automagically load your cpu usage
> based on how many cores are available, etc.
>
>
>
>
>
> Background workers are pretty easy to use and have a comprehensive use
> model.
>
>
>
>
>
> Async delegates(using beginInvoke(IAsyncCallback, object) are easy to use to
> and easy to read.
>
>
>
>
>
> Whichever method you use, you will need to Invoke/Dispatch your control
> updates when using Winforms/WPF respectively.
>
>
>
>
>
> It looks like you are using winforms, so here is a quick pseudo-example
> where I am using a common method that takes an Action as a parameter and
> decides whether to invoke or not::
>
>
>
> public void UpdateDocument(Action action)
>
> {
>
> if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> coming from a thread other than the GUI
>
> {
>
> _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> thread
>
> }
>
> else
>
> {
>
> action();//Came from the same thread as the GUI, so no
> invocation required
>
> }
>
> }
>
>
>
>
>
> In the updating method of whichever threading model you chose, you can use
> the above method like so::
>
>
>
>
>
>
>
> UpdateDocument(new Action(delegate()
>
> {
>
> //Put your control updating code here.
>
> //Example:
>
> lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
>
> }));
>
>
>
>
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 3:42 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> So, I've been exercising my app on the machine, and for the most parts,
> things are working OK, though it seems a bit "sluggish" to me. For example,
> when I single-step, it takes a good 1/2 second or more to execute a line of
> G-code containing nothing more than a single comment. When running, the DROs
> update in significant increments, rather than the relatively smooth updates
> I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I
> would expect it to appear smoother. Could still be problems in my code, so
> none of this concerns me at all at this early stage of the game.
>
> However, in working on the problem of the mis-executing DSP threads, I've
> discovered something really odd. I tested the two programs in question under
> KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they
> both execute correctly first time, every time, without fail. But, run them
> under my app, using the few lines of code posted last night, and the threads
> start, may, or may not, make the first move, then go out to lunch. KMotion
> confirms the threads remain running long after they should have terminated,
> so they seem to be stuck waiting for..... something. Now, here's the bizarre
> part - If I open KMotionCNC - I don't do anything else, just open the app -
> the thread immediately picks up and runs to completion correctly! If I just
> leave KMotionCNC running alongside my app, both DSP programs work perfectly
> every time. In addition, one of them uses a MsgBox to give a message to the
> user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does
> not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> launched from MY app!
>
> What is going on here? What is KMotionCNC doing that affects my DSP programs
> in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did
> NOT launch the threads? Is there some buffer or FIFO somewhere that's
> filling up and blocking communications? I'm at a total loss here...
>
> Regards,
> Ray L.
>
Group: DynoMotion Message: 3442 From: Brad Murry Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Who you calling Gary?  ;)

 

Clarify KM”gasket” please.

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Wednesday, January 25, 2012 5:34 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Gary,

I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume that could be used to push GUI updates from my KM "gasket" when something changes, rather than pulling them from the main app, right?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Ray,
>
>
>
> I would ditch the timer as well, using a service thread to interact with the
> kflop will be much smoother.
>
>
>
> Instead of running your updates via your timer's callback you can either use
> the BackgroundWorker or an Async Delegate or parallel task if using .net4.0
>
>
>
>
>
>
>
> Parallel tasks are best because the will automagically load your cpu usage
> based on how many cores are available, etc.
>
>
>
>
>
> Background workers are pretty easy to use and have a comprehensive use
> model.
>
>
>
>
>
> Async delegates(using beginInvoke(IAsyncCallback, object) are easy to use to
> and easy to read.
>
>
>
>
>
> Whichever method you use, you will need to Invoke/Dispatch your control
> updates when using Winforms/WPF respectively.
>
>
>
>
>
> It looks like you are using winforms, so here is a quick pseudo-example
> where I am using a common method that takes an Action as a parameter and
> decides whether to invoke or not::
>
>
>
> public void UpdateDocument(Action action)
>
> {
>
> if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> coming from a thread other than the GUI
>
> {
>
> _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> thread
>
> }
>
> else
>
> {
>
> action();//Came from the same thread as the GUI, so no
> invocation required
>
> }
>
> }
>
>
>
>
>
> In the updating method of whichever threading model you chose, you can use
> the above method like so::
>
>
>
>
>
>
>
> UpdateDocument(new Action(delegate()
>
> {
>
> //Put your control updating code here.
>
> //Example:
>
> lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
>
> }));
>
>
>
>
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 3:42 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> So, I've been exercising my app on the machine, and for the most parts,
> things are working OK, though it seems a bit "sluggish" to me. For example,
> when I single-step, it takes a good 1/2 second or more to execute a line of
> G-code containing nothing more than a single comment. When running, the DROs
> update in significant increments, rather than the relatively smooth updates
> I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I
> would expect it to appear smoother. Could still be problems in my code, so
> none of this concerns me at all at this early stage of the game.
>
> However, in working on the problem of the mis-executing DSP threads, I've
> discovered something really odd. I tested the two programs in question under
> KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they
> both execute correctly first time, every time, without fail. But, run them
> under my app, using the few lines of code posted last night, and the threads
> start, may, or may not, make the first move, then go out to lunch. KMotion
> confirms the threads remain running long after they should have terminated,
> so they seem to be stuck waiting for..... something. Now, here's the bizarre
> part - If I open KMotionCNC - I don't do anything else, just open the app -
> the thread immediately picks up and runs to completion correctly! If I just
> leave KMotionCNC running alongside my app, both DSP programs work perfectly
> every time. In addition, one of them uses a MsgBox to give a message to the
> user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does
> not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> launched from MY app!
>
> What is going on here? What is KMotionCNC doing that affects my DSP programs
> in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did
> NOT launch the threads? Is there some buffer or FIFO somewhere that's
> filling up and blocking communications? I'm at a total loss here...
>
> Regards,
> Ray L.
>

Group: DynoMotion Message: 3443 From: himykabibble Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Sorry - too many projects, too many people.... :-)

I have a layer between my GUI and dotNet, to keep the GUI "clean" and high-level. All communications passes through that layer, and it also allows me to pull dotNet out, and replace the gasket with a simulator, to test the GUI stand-alone, and force all the possible states.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Who you calling Gary? ;)
>
>
>
> Clarify KM"gasket" please.
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 5:34 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Gary,
>
> I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume that
> could be used to push GUI updates from my KM "gasket" when something
> changes, rather than pulling them from the main app, right?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> >
> > I would ditch the timer as well, using a service thread to interact with
> the
> > kflop will be much smoother.
> >
> >
> >
> > Instead of running your updates via your timer's callback you can either
> use
> > the BackgroundWorker or an Async Delegate or parallel task if using
> .net4.0
> >
> >
> >
> >
> >
> >
> >
> > Parallel tasks are best because the will automagically load your cpu usage
> > based on how many cores are available, etc.
> >
> >
> >
> >
> >
> > Background workers are pretty easy to use and have a comprehensive use
> > model.
> >
> >
> >
> >
> >
> > Async delegates(using beginInvoke(IAsyncCallback, object) are easy to use
> to
> > and easy to read.
> >
> >
> >
> >
> >
> > Whichever method you use, you will need to Invoke/Dispatch your control
> > updates when using Winforms/WPF respectively.
> >
> >
> >
> >
> >
> > It looks like you are using winforms, so here is a quick pseudo-example
> > where I am using a common method that takes an Action as a parameter and
> > decides whether to invoke or not::
> >
> >
> >
> > public void UpdateDocument(Action action)
> >
> > {
> >
> > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > coming from a thread other than the GUI
> >
> > {
> >
> > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > thread
> >
> > }
> >
> > else
> >
> > {
> >
> > action();//Came from the same thread as the GUI, so no
> > invocation required
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > In the updating method of whichever threading model you chose, you can use
> > the above method like so::
> >
> >
> >
> >
> >
> >
> >
> > UpdateDocument(new Action(delegate()
> >
> > {
> >
> > //Put your control updating code here.
> >
> > //Example:
> >
> > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> >
> > }));
> >
> >
> >
> >
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 3:42 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > So, I've been exercising my app on the machine, and for the most parts,
> > things are working OK, though it seems a bit "sluggish" to me. For
> example,
> > when I single-step, it takes a good 1/2 second or more to execute a line
> of
> > G-code containing nothing more than a single comment. When running, the
> DROs
> > update in significant increments, rather than the relatively smooth
> updates
> > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I
> > would expect it to appear smoother. Could still be problems in my code, so
> > none of this concerns me at all at this early stage of the game.
> >
> > However, in working on the problem of the mis-executing DSP threads, I've
> > discovered something really odd. I tested the two programs in question
> under
> > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they
> > both execute correctly first time, every time, without fail. But, run them
> > under my app, using the few lines of code posted last night, and the
> threads
> > start, may, or may not, make the first move, then go out to lunch. KMotion
> > confirms the threads remain running long after they should have
> terminated,
> > so they seem to be stuck waiting for..... something. Now, here's the
> bizarre
> > part - If I open KMotionCNC - I don't do anything else, just open the app
> -
> > the thread immediately picks up and runs to completion correctly! If I
> just
> > leave KMotionCNC running alongside my app, both DSP programs work
> perfectly
> > every time. In addition, one of them uses a MsgBox to give a message to
> the
> > user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does
> > not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> > launched from MY app!
> >
> > What is going on here? What is KMotionCNC doing that affects my DSP
> programs
> > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did
> > NOT launch the threads? Is there some buffer or FIFO somewhere that's
> > filling up and blocking communications? I'm at a total loss here...
> >
> > Regards,
> > Ray L.
> >
>
Group: DynoMotion Message: 3444 From: Brad Murry Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Absolutely, you can push from wherever, but you will need to pass a reference to a control you are using(best bet is the main window) to your middle layer.

 

If you used WPF you would not need to maintain a reference to any control as you could walk up the tree to the current Dispatcher.

 

-Brad

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Wednesday, January 25, 2012 6:14 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

Sorry - too many projects, too many people.... :-)

I have a layer between my GUI and dotNet, to keep the GUI "clean" and high-level. All communications passes through that layer, and it also allows me to pull dotNet out, and replace the gasket with a simulator, to test the GUI stand-alone, and force all the possible states.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Who you calling Gary? ;)
>
>
>
> Clarify KM"gasket" please.
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 5:34 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Gary,
>
> I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume that
> could be used to push GUI updates from my KM "gasket" when something
> changes, rather than pulling them from the main app, right?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> >
> > I would ditch the timer as well, using a service thread to interact with
> the
> > kflop will be much smoother.
> >
> >
> >
> > Instead of running your updates via your timer's callback you can either
> use
> > the BackgroundWorker or an Async Delegate or parallel task if using
> .net4.0
> >
> >
> >
> >
> >
> >
> >
> > Parallel tasks are best because the will automagically load your cpu usage
> > based on how many cores are available, etc.
> >
> >
> >
> >
> >
> > Background workers are pretty easy to use and have a comprehensive use
> > model.
> >
> >
> >
> >
> >
> > Async delegates(using beginInvoke(IAsyncCallback, object) are easy to use
> to
> > and easy to read.
> >
> >
> >
> >
> >
> > Whichever method you use, you will need to Invoke/Dispatch your control
> > updates when using Winforms/WPF respectively.
> >
> >
> >
> >
> >
> > It looks like you are using winforms, so here is a quick pseudo-example
> > where I am using a common method that takes an Action as a parameter and
> > decides whether to invoke or not::
> >
> >
> >
> > public void UpdateDocument(Action action)
> >
> > {
> >
> > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > coming from a thread other than the GUI
> >
> > {
> >
> > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > thread
> >
> > }
> >
> > else
> >
> > {
> >
> > action();//Came from the same thread as the GUI, so no
> > invocation required
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > In the updating method of whichever threading model you chose, you can use
> > the above method like so::
> >
> >
> >
> >
> >
> >
> >
> > UpdateDocument(new Action(delegate()
> >
> > {
> >
> > //Put your control updating code here.
> >
> > //Example:
> >
> > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> >
> > }));
> >
> >
> >
> >
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 3:42 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > So, I've been exercising my app on the machine, and for the most parts,
> > things are working OK, though it seems a bit "sluggish" to me. For
> example,
> > when I single-step, it takes a good 1/2 second or more to execute a line
> of
> > G-code containing nothing more than a single comment. When running, the
> DROs
> > update in significant increments, rather than the relatively smooth
> updates
> > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so I
> > would expect it to appear smoother. Could still be problems in my code, so
> > none of this concerns me at all at this early stage of the game.
> >
> > However, in working on the problem of the mis-executing DSP threads, I've
> > discovered something really odd. I tested the two programs in question
> under
> > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC, they
> > both execute correctly first time, every time, without fail. But, run them
> > under my app, using the few lines of code posted last night, and the
> threads
> > start, may, or may not, make the first move, then go out to lunch. KMotion
> > confirms the threads remain running long after they should have
> terminated,
> > so they seem to be stuck waiting for..... something. Now, here's the
> bizarre
> > part - If I open KMotionCNC - I don't do anything else, just open the app
> -
> > the thread immediately picks up and runs to completion correctly! If I
> just
> > leave KMotionCNC running alongside my app, both DSP programs work
> perfectly
> > every time. In addition, one of them uses a MsgBox to give a message to
> the
> > user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox does
> > not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> > launched from MY app!
> >
> > What is going on here? What is KMotionCNC doing that affects my DSP
> programs
> > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it did
> > NOT launch the threads? Is there some buffer or FIFO somewhere that's
> > filling up and blocking communications? I'm at a total loss here...
> >
> > Regards,
> > Ray L.
> >
>

Group: DynoMotion Message: 3445 From: himykabibble Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I'm not changing to WPF at this late stage of the game! :-)

I can see how I could use parallel threads to make the display updates more efficient (launch separate threads to update all the DROs, and other controls). I assume the wonders of .NET will deal with all the concurrency issues that could create in accessing especially dotNet objects? I just checked and my update loop is running only about 5X/second right now, though GUI response is generally not bad. It's mostly the DRO updates that really need to be sped up.

How would you do it?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Absolutely, you can push from wherever, but you will need to pass a
> reference to a control you are using(best bet is the main window) to your
> middle layer.
>
>
>
> If you used WPF you would not need to maintain a reference to any control as
> you could walk up the tree to the current Dispatcher.
>
>
>
> -Brad
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 6:14 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> Sorry - too many projects, too many people.... :-)
>
> I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> high-level. All communications passes through that layer, and it also allows
> me to pull dotNet out, and replace the gasket with a simulator, to test the
> GUI stand-alone, and force all the possible states.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Who you calling Gary? ;)
> >
> >
> >
> > Clarify KM"gasket" please.
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 5:34 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Gary,
> >
> > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume
> that
> > could be used to push GUI updates from my KM "gasket" when something
> > changes, rather than pulling them from the main app, right?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > I would ditch the timer as well, using a service thread to interact with
> > the
> > > kflop will be much smoother.
> > >
> > >
> > >
> > > Instead of running your updates via your timer's callback you can either
> > use
> > > the BackgroundWorker or an Async Delegate or parallel task if using
> > .net4.0
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Parallel tasks are best because the will automagically load your cpu
> usage
> > > based on how many cores are available, etc.
> > >
> > >
> > >
> > >
> > >
> > > Background workers are pretty easy to use and have a comprehensive use
> > > model.
> > >
> > >
> > >
> > >
> > >
> > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy to
> use
> > to
> > > and easy to read.
> > >
> > >
> > >
> > >
> > >
> > > Whichever method you use, you will need to Invoke/Dispatch your control
> > > updates when using Winforms/WPF respectively.
> > >
> > >
> > >
> > >
> > >
> > > It looks like you are using winforms, so here is a quick pseudo-example
> > > where I am using a common method that takes an Action as a parameter and
> > > decides whether to invoke or not::
> > >
> > >
> > >
> > > public void UpdateDocument(Action action)
> > >
> > > {
> > >
> > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > coming from a thread other than the GUI
> > >
> > > {
> > >
> > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > thread
> > >
> > > }
> > >
> > > else
> > >
> > > {
> > >
> > > action();//Came from the same thread as the GUI, so no
> > > invocation required
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > In the updating method of whichever threading model you chose, you can
> use
> > > the above method like so::
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > UpdateDocument(new Action(delegate()
> > >
> > > {
> > >
> > > //Put your control updating code here.
> > >
> > > //Example:
> > >
> > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > >
> > > }));
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > So, I've been exercising my app on the machine, and for the most parts,
> > > things are working OK, though it seems a bit "sluggish" to me. For
> > example,
> > > when I single-step, it takes a good 1/2 second or more to execute a line
> > of
> > > G-code containing nothing more than a single comment. When running, the
> > DROs
> > > update in significant increments, rather than the relatively smooth
> > updates
> > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so
> I
> > > would expect it to appear smoother. Could still be problems in my code,
> so
> > > none of this concerns me at all at this early stage of the game.
> > >
> > > However, in working on the problem of the mis-executing DSP threads,
> I've
> > > discovered something really odd. I tested the two programs in question
> > under
> > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> they
> > > both execute correctly first time, every time, without fail. But, run
> them
> > > under my app, using the few lines of code posted last night, and the
> > threads
> > > start, may, or may not, make the first move, then go out to lunch.
> KMotion
> > > confirms the threads remain running long after they should have
> > terminated,
> > > so they seem to be stuck waiting for..... something. Now, here's the
> > bizarre
> > > part - If I open KMotionCNC - I don't do anything else, just open the
> app
> > -
> > > the thread immediately picks up and runs to completion correctly! If I
> > just
> > > leave KMotionCNC running alongside my app, both DSP programs work
> > perfectly
> > > every time. In addition, one of them uses a MsgBox to give a message to
> > the
> > > user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox
> does
> > > not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> > > launched from MY app!
> > >
> > > What is going on here? What is KMotionCNC doing that affects my DSP
> > programs
> > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it
> did
> > > NOT launch the threads? Is there some buffer or FIFO somewhere that's
> > > filling up and blocking communications? I'm at a total loss here...
> > >
> > > Regards,
> > > Ray L.
> > >
> >
>
Group: DynoMotion Message: 3446 From: Brad Murry Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...


First off, you never want to have too many threads running, technically you can only have one run per core and anything after that is going to be time slicing.

 

 

If I was making a small lightweight winforms app in .net3.5(like the HTML controller ;-)  ), I would/am use/ing the invoke methods I outlined earlier.

 

  Inside of it, I basically have an endless loop running on a separate worker thread using the simple BackgroundWorker class.  The endless loop sleeps every 100ms and I have the DRO’s updating on that time slice.  Within the loop I also have a counter that I increment/reset every 5 cycles and when that happens I update the less important items.

 

Very basic setup that only uses one additional thread that updates the DRO’s 1/10th a second and then things like LED’s, enable status, etc… get updated every ½ a second.

 

I will re-upload my source so you can see how it works.

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Wednesday, January 25, 2012 6:49 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

I'm not changing to WPF at this late stage of the game! :-)

I can see how I could use parallel threads to make the display updates more efficient (launch separate threads to update all the DROs, and other controls). I assume the wonders of .NET will deal with all the concurrency issues that could create in accessing especially dotNet objects? I just checked and my update loop is running only about 5X/second right now, though GUI response is generally not bad. It's mostly the DRO updates that really need to be sped up.

How would you do it?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Absolutely, you can push from wherever, but you will need to pass a
> reference to a control you are using(best bet is the main window) to your
> middle layer.
>
>
>
> If you used WPF you would not need to maintain a reference to any control as
> you could walk up the tree to the current Dispatcher.
>
>
>
> -Brad
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 6:14 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> Sorry - too many projects, too many people.... :-)
>
> I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> high-level. All communications passes through that layer, and it also allows
> me to pull dotNet out, and replace the gasket with a simulator, to test the
> GUI stand-alone, and force all the possible states.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Who you calling Gary? ;)
> >
> >
> >
> > Clarify KM"gasket" please.
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 5:34 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Gary,
> >
> > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume
> that
> > could be used to push GUI updates from my KM "gasket" when something
> > changes, rather than pulling them from the main app, right?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > I would ditch the timer as well, using a service thread to interact with
> > the
> > > kflop will be much smoother.
> > >
> > >
> > >
> > > Instead of running your updates via your timer's callback you can either
> > use
> > > the BackgroundWorker or an Async Delegate or parallel task if using
> > .net4.0
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > Parallel tasks are best because the will automagically load your cpu
> usage
> > > based on how many cores are available, etc.
> > >
> > >
> > >
> > >
> > >
> > > Background workers are pretty easy to use and have a comprehensive use
> > > model.
> > >
> > >
> > >
> > >
> > >
> > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy to
> use
> > to
> > > and easy to read.
> > >
> > >
> > >
> > >
> > >
> > > Whichever method you use, you will need to Invoke/Dispatch your control
> > > updates when using Winforms/WPF respectively.
> > >
> > >
> > >
> > >
> > >
> > > It looks like you are using winforms, so here is a quick pseudo-example
> > > where I am using a common method that takes an Action as a parameter and
> > > decides whether to invoke or not::
> > >
> > >
> > >
> > > public void UpdateDocument(Action action)
> > >
> > > {
> > >
> > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > coming from a thread other than the GUI
> > >
> > > {
> > >
> > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > thread
> > >
> > > }
> > >
> > > else
> > >
> > > {
> > >
> > > action();//Came from the same thread as the GUI, so no
> > > invocation required
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > In the updating method of whichever threading model you chose, you can
> use
> > > the above method like so::
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > UpdateDocument(new Action(delegate()
> > >
> > > {
> > >
> > > //Put your control updating code here.
> > >
> > > //Example:
> > >
> > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > >
> > > }));
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > So, I've been exercising my app on the machine, and for the most parts,
> > > things are working OK, though it seems a bit "sluggish" to me. For
> > example,
> > > when I single-step, it takes a good 1/2 second or more to execute a line
> > of
> > > G-code containing nothing more than a single comment. When running, the
> > DROs
> > > update in significant increments, rather than the relatively smooth
> > updates
> > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec, so
> I
> > > would expect it to appear smoother. Could still be problems in my code,
> so
> > > none of this concerns me at all at this early stage of the game.
> > >
> > > However, in working on the problem of the mis-executing DSP threads,
> I've
> > > discovered something really odd. I tested the two programs in question
> > under
> > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> they
> > > both execute correctly first time, every time, without fail. But, run
> them
> > > under my app, using the few lines of code posted last night, and the
> > threads
> > > start, may, or may not, make the first move, then go out to lunch.
> KMotion
> > > confirms the threads remain running long after they should have
> > terminated,
> > > so they seem to be stuck waiting for..... something. Now, here's the
> > bizarre
> > > part - If I open KMotionCNC - I don't do anything else, just open the
> app
> > -
> > > the thread immediately picks up and runs to completion correctly! If I
> > just
> > > leave KMotionCNC running alongside my app, both DSP programs work
> > perfectly
> > > every time. In addition, one of them uses a MsgBox to give a message to
> > the
> > > user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox
> does
> > > not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> > > launched from MY app!
> > >
> > > What is going on here? What is KMotionCNC doing that affects my DSP
> > programs
> > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it
> did
> > > NOT launch the threads? Is there some buffer or FIFO somewhere that's
> > > filling up and blocking communications? I'm at a total loss here...
> > >
> > > Regards,
> > > Ray L.
> > >
> >
>

Group: DynoMotion Message: 3448 From: himykabibble Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Here's where I keep getting stuck - I believe the bulk of the display update time is getting the information from dotNet, not actually updating the controls. I already update the DROs more often than the other controls, by just doing the DROs on every timer tick, and the others on alternate ticks. How will another thread improve performance, if the bottleneck is getting the update data (which comes primarily from MainStatus), particularly since I have to go through an invoke to modify each control?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
>
> First off, you never want to have too many threads running, technically you
> can only have one run per core and anything after that is going to be time
> slicing.
>
>
>
>
>
> If I was making a small lightweight winforms app in .net3.5(like the HTML
> controller ;-) ), I would/am use/ing the invoke methods I outlined earlier.
>
>
>
> Inside of it, I basically have an endless loop running on a separate
> worker thread using the simple BackgroundWorker class. The endless loop
> sleeps every 100ms and I have the DRO's updating on that time slice. Within
> the loop I also have a counter that I increment/reset every 5 cycles and
> when that happens I update the less important items.
>
>
>
> Very basic setup that only uses one additional thread that updates the DRO's
> 1/10th a second and then things like LED's, enable status, etc… get updated
> every ½ a second.
>
>
>
> I will re-upload my source so you can see how it works.
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 6:49 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> I'm not changing to WPF at this late stage of the game! :-)
>
> I can see how I could use parallel threads to make the display updates more
> efficient (launch separate threads to update all the DROs, and other
> controls). I assume the wonders of .NET will deal with all the concurrency
> issues that could create in accessing especially dotNet objects? I just
> checked and my update loop is running only about 5X/second right now, though
> GUI response is generally not bad. It's mostly the DRO updates that really
> need to be sped up.
>
> How would you do it?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Absolutely, you can push from wherever, but you will need to pass a
> > reference to a control you are using(best bet is the main window) to your
> > middle layer.
> >
> >
> >
> > If you used WPF you would not need to maintain a reference to any control
> as
> > you could walk up the tree to the current Dispatcher.
> >
> >
> >
> > -Brad
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 6:14 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > Sorry - too many projects, too many people.... :-)
> >
> > I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> > high-level. All communications passes through that layer, and it also
> allows
> > me to pull dotNet out, and replace the gasket with a simulator, to test
> the
> > GUI stand-alone, and force all the possible states.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Who you calling Gary? ;)
> > >
> > >
> > >
> > > Clarify KM"gasket" please.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Gary,
> > >
> > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume
> > that
> > > could be used to push GUI updates from my KM "gasket" when something
> > > changes, rather than pulling them from the main app, right?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > >
> > > > I would ditch the timer as well, using a service thread to interact
> with
> > > the
> > > > kflop will be much smoother.
> > > >
> > > >
> > > >
> > > > Instead of running your updates via your timer's callback you can
> either
> > > use
> > > > the BackgroundWorker or an Async Delegate or parallel task if using
> > > .net4.0
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Parallel tasks are best because the will automagically load your cpu
> > usage
> > > > based on how many cores are available, etc.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Background workers are pretty easy to use and have a comprehensive use
> > > > model.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy to
> > use
> > > to
> > > > and easy to read.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Whichever method you use, you will need to Invoke/Dispatch your
> control
> > > > updates when using Winforms/WPF respectively.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > It looks like you are using winforms, so here is a quick
> pseudo-example
> > > > where I am using a common method that takes an Action as a parameter
> and
> > > > decides whether to invoke or not::
> > > >
> > > >
> > > >
> > > > public void UpdateDocument(Action action)
> > > >
> > > > {
> > > >
> > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > coming from a thread other than the GUI
> > > >
> > > > {
> > > >
> > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > thread
> > > >
> > > > }
> > > >
> > > > else
> > > >
> > > > {
> > > >
> > > > action();//Came from the same thread as the GUI, so no
> > > > invocation required
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > In the updating method of whichever threading model you chose, you can
> > use
> > > > the above method like so::
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > UpdateDocument(new Action(delegate()
> > > >
> > > > {
> > > >
> > > > //Put your control updating code here.
> > > >
> > > > //Example:
> > > >
> > > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > > >
> > > > }));
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > So, I've been exercising my app on the machine, and for the most
> parts,
> > > > things are working OK, though it seems a bit "sluggish" to me. For
> > > example,
> > > > when I single-step, it takes a good 1/2 second or more to execute a
> line
> > > of
> > > > G-code containing nothing more than a single comment. When running,
> the
> > > DROs
> > > > update in significant increments, rather than the relatively smooth
> > > updates
> > > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec,
> so
> > I
> > > > would expect it to appear smoother. Could still be problems in my
> code,
> > so
> > > > none of this concerns me at all at this early stage of the game.
> > > >
> > > > However, in working on the problem of the mis-executing DSP threads,
> > I've
> > > > discovered something really odd. I tested the two programs in question
> > > under
> > > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> > they
> > > > both execute correctly first time, every time, without fail. But, run
> > them
> > > > under my app, using the few lines of code posted last night, and the
> > > threads
> > > > start, may, or may not, make the first move, then go out to lunch.
> > KMotion
> > > > confirms the threads remain running long after they should have
> > > terminated,
> > > > so they seem to be stuck waiting for..... something. Now, here's the
> > > bizarre
> > > > part - If I open KMotionCNC - I don't do anything else, just open the
> > app
> > > -
> > > > the thread immediately picks up and runs to completion correctly! If I
> > > just
> > > > leave KMotionCNC running alongside my app, both DSP programs work
> > > perfectly
> > > > every time. In addition, one of them uses a MsgBox to give a message
> to
> > > the
> > > > user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox
> > does
> > > > not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> > > > launched from MY app!
> > > >
> > > > What is going on here? What is KMotionCNC doing that affects my DSP
> > > programs
> > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it
> > did
> > > > NOT launch the threads? Is there some buffer or FIFO somewhere that's
> > > > filling up and blocking communications? I'm at a total loss here...
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > >
> >
>
Group: DynoMotion Message: 3449 From: Brad Murry Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

The only thing I will add at this point is try it and you will see.

 

 

I will add that  MM uses a multi-threading model, has a lot more rendering going on that a winforms app, also does openGL toolpath display and I can see out to 4-5 decimals changing smoothly during feed moves.

 

 

Nowadays any non-trivial app requires multi-threading.

 

 

-Brad

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Wednesday, January 25, 2012 8:59 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

Here's where I keep getting stuck - I believe the bulk of the display update time is getting the information from dotNet, not actually updating the controls. I already update the DROs more often than the other controls, by just doing the DROs on every timer tick, and the others on alternate ticks. How will another thread improve performance, if the bottleneck is getting the update data (which comes primarily from MainStatus), particularly since I have to go through an invoke to modify each control?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
>
> First off, you never want to have too many threads running, technically you
> can only have one run per core and anything after that is going to be time
> slicing.
>
>
>
>
>
> If I was making a small lightweight winforms app in .net3.5(like the HTML
> controller ;-) ), I would/am use/ing the invoke methods I outlined earlier.
>
>
>
> Inside of it, I basically have an endless loop running on a separate
> worker thread using the simple BackgroundWorker class. The endless loop
> sleeps every 100ms and I have the DRO's updating on that time slice. Within
> the loop I also have a counter that I increment/reset every 5 cycles and
> when that happens I update the less important items.
>
>
>
> Very basic setup that only uses one additional thread that updates the DRO's
> 1/10th a second and then things like LED's, enable status, etc… get updated
> every ½ a second.
>
>
>
> I will re-upload my source so you can see how it works.
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 6:49 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> I'm not changing to WPF at this late stage of the game! :-)
>
> I can see how I could use parallel threads to make the display updates more
> efficient (launch separate threads to update all the DROs, and other
> controls). I assume the wonders of .NET will deal with all the concurrency
> issues that could create in accessing especially dotNet objects? I just
> checked and my update loop is running only about 5X/second right now, though
> GUI response is generally not bad. It's mostly the DRO updates that really
> need to be sped up.
>
> How would you do it?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Absolutely, you can push from wherever, but you will need to pass a
> > reference to a control you are using(best bet is the main window) to your
> > middle layer.
> >
> >
> >
> > If you used WPF you would not need to maintain a reference to any control
> as
> > you could walk up the tree to the current Dispatcher.
> >
> >
> >
> > -Brad
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 6:14 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > Sorry - too many projects, too many people.... :-)
> >
> > I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> > high-level. All communications passes through that layer, and it also
> allows
> > me to pull dotNet out, and replace the gasket with a simulator, to test
> the
> > GUI stand-alone, and force all the possible states.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Who you calling Gary? ;)
> > >
> > >
> > >
> > > Clarify KM"gasket" please.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Gary,
> > >
> > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I assume
> > that
> > > could be used to push GUI updates from my KM "gasket" when something
> > > changes, rather than pulling them from the main app, right?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > >
> > > > I would ditch the timer as well, using a service thread to interact
> with
> > > the
> > > > kflop will be much smoother.
> > > >
> > > >
> > > >
> > > > Instead of running your updates via your timer's callback you can
> either
> > > use
> > > > the BackgroundWorker or an Async Delegate or parallel task if using
> > > .net4.0
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Parallel tasks are best because the will automagically load your cpu
> > usage
> > > > based on how many cores are available, etc.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Background workers are pretty easy to use and have a comprehensive use
> > > > model.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy to
> > use
> > > to
> > > > and easy to read.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Whichever method you use, you will need to Invoke/Dispatch your
> control
> > > > updates when using Winforms/WPF respectively.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > It looks like you are using winforms, so here is a quick
> pseudo-example
> > > > where I am using a common method that takes an Action as a parameter
> and
> > > > decides whether to invoke or not::
> > > >
> > > >
> > > >
> > > > public void UpdateDocument(Action action)
> > > >
> > > > {
> > > >
> > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > coming from a thread other than the GUI
> > > >
> > > > {
> > > >
> > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > thread
> > > >
> > > > }
> > > >
> > > > else
> > > >
> > > > {
> > > >
> > > > action();//Came from the same thread as the GUI, so no
> > > > invocation required
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > In the updating method of whichever threading model you chose, you can
> > use
> > > > the above method like so::
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > UpdateDocument(new Action(delegate()
> > > >
> > > > {
> > > >
> > > > //Put your control updating code here.
> > > >
> > > > //Example:
> > > >
> > > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > > >
> > > > }));
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > So, I've been exercising my app on the machine, and for the most
> parts,
> > > > things are working OK, though it seems a bit "sluggish" to me. For
> > > example,
> > > > when I single-step, it takes a good 1/2 second or more to execute a
> line
> > > of
> > > > G-code containing nothing more than a single comment. When running,
> the
> > > DROs
> > > > update in significant increments, rather than the relatively smooth
> > > updates
> > > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec,
> so
> > I
> > > > would expect it to appear smoother. Could still be problems in my
> code,
> > so
> > > > none of this concerns me at all at this early stage of the game.
> > > >
> > > > However, in working on the problem of the mis-executing DSP threads,
> > I've
> > > > discovered something really odd. I tested the two programs in question
> > > under
> > > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> > they
> > > > both execute correctly first time, every time, without fail. But, run
> > them
> > > > under my app, using the few lines of code posted last night, and the
> > > threads
> > > > start, may, or may not, make the first move, then go out to lunch.
> > KMotion
> > > > confirms the threads remain running long after they should have
> > > terminated,
> > > > so they seem to be stuck waiting for..... something. Now, here's the
> > > bizarre
> > > > part - If I open KMotionCNC - I don't do anything else, just open the
> > app
> > > -
> > > > the thread immediately picks up and runs to completion correctly! If I
> > > just
> > > > leave KMotionCNC running alongside my app, both DSP programs work
> > > perfectly
> > > > every time. In addition, one of them uses a MsgBox to give a message
> to
> > > the
> > > > user. If I have KMotionCNC minimized or otherwise hidden, this MsgBox
> > does
> > > > not appear UNTIL KMotionCNC get focus, even though the DSP thread was
> > > > launched from MY app!
> > > >
> > > > What is going on here? What is KMotionCNC doing that affects my DSP
> > > programs
> > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when it
> > did
> > > > NOT launch the threads? Is there some buffer or FIFO somewhere that's
> > > > filling up and blocking communications? I'm at a total loss here...
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > >
> >
>

Group: DynoMotion Message: 3450 From: himykabibble Date: 1/25/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Well, I've been trying for the last couple of hours, but keep running into obstacles that would require signifcant re-factoring. I can clearly see the advantage, and would have taken that approach from the start had I known it was available, but the code isn't structured that way right now. I will still do it, but I'm much more focused right now on getting the bugs out, than opitmizing performance. The number of unresolved and worked-around issues is getting in the way so I'm reluctant to make big changes that will undoubtedly raise new issues. I'd really like to have something I can actually start to use within the next few days.

If I can figure out how to get the tool table working, and hopefully resolve the disconnect/connect and Dispose issues, I think I'll have something I can start to use.

Regards,
Ray L.


--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> The only thing I will add at this point is try it and you will see.
>
>
>
>
>
> I will add that MM uses a multi-threading model, has a lot more rendering
> going on that a winforms app, also does openGL toolpath display and I can
> see out to 4-5 decimals changing smoothly during feed moves.
>
>
>
>
>
> Nowadays any non-trivial app requires multi-threading.
>
>
>
>
>
> -Brad
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 8:59 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> Here's where I keep getting stuck - I believe the bulk of the display update
> time is getting the information from dotNet, not actually updating the
> controls. I already update the DROs more often than the other controls, by
> just doing the DROs on every timer tick, and the others on alternate ticks.
> How will another thread improve performance, if the bottleneck is getting
> the update data (which comes primarily from MainStatus), particularly since
> I have to go through an invoke to modify each control?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> >
> > First off, you never want to have too many threads running, technically
> you
> > can only have one run per core and anything after that is going to be time
> > slicing.
> >
> >
> >
> >
> >
> > If I was making a small lightweight winforms app in .net3.5(like the HTML
> > controller ;-) ), I would/am use/ing the invoke methods I outlined
> earlier.
> >
> >
> >
> > Inside of it, I basically have an endless loop running on a separate
> > worker thread using the simple BackgroundWorker class. The endless loop
> > sleeps every 100ms and I have the DRO's updating on that time slice.
> Within
> > the loop I also have a counter that I increment/reset every 5 cycles and
> > when that happens I update the less important items.
> >
> >
> >
> > Very basic setup that only uses one additional thread that updates the
> DRO's
> > 1/10th a second and then things like LED's, enable status, etc… get
> updated
> > every ½ a second.
> >
> >
> >
> > I will re-upload my source so you can see how it works.
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 6:49 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > I'm not changing to WPF at this late stage of the game! :-)
> >
> > I can see how I could use parallel threads to make the display updates
> more
> > efficient (launch separate threads to update all the DROs, and other
> > controls). I assume the wonders of .NET will deal with all the concurrency
> > issues that could create in accessing especially dotNet objects? I just
> > checked and my update loop is running only about 5X/second right now,
> though
> > GUI response is generally not bad. It's mostly the DRO updates that really
> > need to be sped up.
> >
> > How would you do it?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Absolutely, you can push from wherever, but you will need to pass a
> > > reference to a control you are using(best bet is the main window) to
> your
> > > middle layer.
> > >
> > >
> > >
> > > If you used WPF you would not need to maintain a reference to any
> control
> > as
> > > you could walk up the tree to the current Dispatcher.
> > >
> > >
> > >
> > > -Brad
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > Sorry - too many projects, too many people.... :-)
> > >
> > > I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> > > high-level. All communications passes through that layer, and it also
> > allows
> > > me to pull dotNet out, and replace the gasket with a simulator, to test
> > the
> > > GUI stand-alone, and force all the possible states.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Who you calling Gary? ;)
> > > >
> > > >
> > > >
> > > > Clarify KM"gasket" please.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Gary,
> > > >
> > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> assume
> > > that
> > > > could be used to push GUI updates from my KM "gasket" when something
> > > > changes, rather than pulling them from the main app, right?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Ray,
> > > > >
> > > > >
> > > > >
> > > > > I would ditch the timer as well, using a service thread to interact
> > with
> > > > the
> > > > > kflop will be much smoother.
> > > > >
> > > > >
> > > > >
> > > > > Instead of running your updates via your timer's callback you can
> > either
> > > > use
> > > > > the BackgroundWorker or an Async Delegate or parallel task if using
> > > > .net4.0
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Parallel tasks are best because the will automagically load your cpu
> > > usage
> > > > > based on how many cores are available, etc.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Background workers are pretty easy to use and have a comprehensive
> use
> > > > > model.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy
> to
> > > use
> > > > to
> > > > > and easy to read.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Whichever method you use, you will need to Invoke/Dispatch your
> > control
> > > > > updates when using Winforms/WPF respectively.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > It looks like you are using winforms, so here is a quick
> > pseudo-example
> > > > > where I am using a common method that takes an Action as a parameter
> > and
> > > > > decides whether to invoke or not::
> > > > >
> > > > >
> > > > >
> > > > > public void UpdateDocument(Action action)
> > > > >
> > > > > {
> > > > >
> > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > > coming from a thread other than the GUI
> > > > >
> > > > > {
> > > > >
> > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > thread
> > > > >
> > > > > }
> > > > >
> > > > > else
> > > > >
> > > > > {
> > > > >
> > > > > action();//Came from the same thread as the GUI, so no
> > > > > invocation required
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > In the updating method of whichever threading model you chose, you
> can
> > > use
> > > > > the above method like so::
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > UpdateDocument(new Action(delegate()
> > > > >
> > > > > {
> > > > >
> > > > > //Put your control updating code here.
> > > > >
> > > > > //Example:
> > > > >
> > > > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > > > >
> > > > > }));
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > So, I've been exercising my app on the machine, and for the most
> > parts,
> > > > > things are working OK, though it seems a bit "sluggish" to me. For
> > > > example,
> > > > > when I single-step, it takes a good 1/2 second or more to execute a
> > line
> > > > of
> > > > > G-code containing nothing more than a single comment. When running,
> > the
> > > > DROs
> > > > > update in significant increments, rather than the relatively smooth
> > > > updates
> > > > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec,
> > so
> > > I
> > > > > would expect it to appear smoother. Could still be problems in my
> > code,
> > > so
> > > > > none of this concerns me at all at this early stage of the game.
> > > > >
> > > > > However, in working on the problem of the mis-executing DSP threads,
> > > I've
> > > > > discovered something really odd. I tested the two programs in
> question
> > > > under
> > > > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> > > they
> > > > > both execute correctly first time, every time, without fail. But,
> run
> > > them
> > > > > under my app, using the few lines of code posted last night, and the
> > > > threads
> > > > > start, may, or may not, make the first move, then go out to lunch.
> > > KMotion
> > > > > confirms the threads remain running long after they should have
> > > > terminated,
> > > > > so they seem to be stuck waiting for..... something. Now, here's the
> > > > bizarre
> > > > > part - If I open KMotionCNC - I don't do anything else, just open
> the
> > > app
> > > > -
> > > > > the thread immediately picks up and runs to completion correctly! If
> I
> > > > just
> > > > > leave KMotionCNC running alongside my app, both DSP programs work
> > > > perfectly
> > > > > every time. In addition, one of them uses a MsgBox to give a message
> > to
> > > > the
> > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> MsgBox
> > > does
> > > > > not appear UNTIL KMotionCNC get focus, even though the DSP thread
> was
> > > > > launched from MY app!
> > > > >
> > > > > What is going on here? What is KMotionCNC doing that affects my DSP
> > > > programs
> > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when
> it
> > > did
> > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> that's
> > > > > filling up and blocking communications? I'm at a total loss here...
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3474 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Well, I moved the display updates to a BackgroundWorker thread by plagiarizing what you do in your HTML app. It was relatively painless, but, surprisingly, didn't really make any perceptible difference in terms of display update performance. It also, not surprisingly, introduced a couple of minor bugs. I have yet to get it to reliably close cleanly. On the FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I still sometimes get a null reference error in UpdateDocument when Dispose is called. Not sure I understand why that's happening.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> The only thing I will add at this point is try it and you will see.
>
>
>
>
>
> I will add that MM uses a multi-threading model, has a lot more rendering
> going on that a winforms app, also does openGL toolpath display and I can
> see out to 4-5 decimals changing smoothly during feed moves.
>
>
>
>
>
> Nowadays any non-trivial app requires multi-threading.
>
>
>
>
>
> -Brad
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Wednesday, January 25, 2012 8:59 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> Here's where I keep getting stuck - I believe the bulk of the display update
> time is getting the information from dotNet, not actually updating the
> controls. I already update the DROs more often than the other controls, by
> just doing the DROs on every timer tick, and the others on alternate ticks.
> How will another thread improve performance, if the bottleneck is getting
> the update data (which comes primarily from MainStatus), particularly since
> I have to go through an invoke to modify each control?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> >
> > First off, you never want to have too many threads running, technically
> you
> > can only have one run per core and anything after that is going to be time
> > slicing.
> >
> >
> >
> >
> >
> > If I was making a small lightweight winforms app in .net3.5(like the HTML
> > controller ;-) ), I would/am use/ing the invoke methods I outlined
> earlier.
> >
> >
> >
> > Inside of it, I basically have an endless loop running on a separate
> > worker thread using the simple BackgroundWorker class. The endless loop
> > sleeps every 100ms and I have the DRO's updating on that time slice.
> Within
> > the loop I also have a counter that I increment/reset every 5 cycles and
> > when that happens I update the less important items.
> >
> >
> >
> > Very basic setup that only uses one additional thread that updates the
> DRO's
> > 1/10th a second and then things like LED's, enable status, etc… get
> updated
> > every ½ a second.
> >
> >
> >
> > I will re-upload my source so you can see how it works.
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 6:49 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > I'm not changing to WPF at this late stage of the game! :-)
> >
> > I can see how I could use parallel threads to make the display updates
> more
> > efficient (launch separate threads to update all the DROs, and other
> > controls). I assume the wonders of .NET will deal with all the concurrency
> > issues that could create in accessing especially dotNet objects? I just
> > checked and my update loop is running only about 5X/second right now,
> though
> > GUI response is generally not bad. It's mostly the DRO updates that really
> > need to be sped up.
> >
> > How would you do it?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Absolutely, you can push from wherever, but you will need to pass a
> > > reference to a control you are using(best bet is the main window) to
> your
> > > middle layer.
> > >
> > >
> > >
> > > If you used WPF you would not need to maintain a reference to any
> control
> > as
> > > you could walk up the tree to the current Dispatcher.
> > >
> > >
> > >
> > > -Brad
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > Sorry - too many projects, too many people.... :-)
> > >
> > > I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> > > high-level. All communications passes through that layer, and it also
> > allows
> > > me to pull dotNet out, and replace the gasket with a simulator, to test
> > the
> > > GUI stand-alone, and force all the possible states.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Who you calling Gary? ;)
> > > >
> > > >
> > > >
> > > > Clarify KM"gasket" please.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Gary,
> > > >
> > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> assume
> > > that
> > > > could be used to push GUI updates from my KM "gasket" when something
> > > > changes, rather than pulling them from the main app, right?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Ray,
> > > > >
> > > > >
> > > > >
> > > > > I would ditch the timer as well, using a service thread to interact
> > with
> > > > the
> > > > > kflop will be much smoother.
> > > > >
> > > > >
> > > > >
> > > > > Instead of running your updates via your timer's callback you can
> > either
> > > > use
> > > > > the BackgroundWorker or an Async Delegate or parallel task if using
> > > > .net4.0
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Parallel tasks are best because the will automagically load your cpu
> > > usage
> > > > > based on how many cores are available, etc.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Background workers are pretty easy to use and have a comprehensive
> use
> > > > > model.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy
> to
> > > use
> > > > to
> > > > > and easy to read.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Whichever method you use, you will need to Invoke/Dispatch your
> > control
> > > > > updates when using Winforms/WPF respectively.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > It looks like you are using winforms, so here is a quick
> > pseudo-example
> > > > > where I am using a common method that takes an Action as a parameter
> > and
> > > > > decides whether to invoke or not::
> > > > >
> > > > >
> > > > >
> > > > > public void UpdateDocument(Action action)
> > > > >
> > > > > {
> > > > >
> > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > > coming from a thread other than the GUI
> > > > >
> > > > > {
> > > > >
> > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > thread
> > > > >
> > > > > }
> > > > >
> > > > > else
> > > > >
> > > > > {
> > > > >
> > > > > action();//Came from the same thread as the GUI, so no
> > > > > invocation required
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > In the updating method of whichever threading model you chose, you
> can
> > > use
> > > > > the above method like so::
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > UpdateDocument(new Action(delegate()
> > > > >
> > > > > {
> > > > >
> > > > > //Put your control updating code here.
> > > > >
> > > > > //Example:
> > > > >
> > > > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > > > >
> > > > > }));
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > So, I've been exercising my app on the machine, and for the most
> > parts,
> > > > > things are working OK, though it seems a bit "sluggish" to me. For
> > > > example,
> > > > > when I single-step, it takes a good 1/2 second or more to execute a
> > line
> > > > of
> > > > > G-code containing nothing more than a single comment. When running,
> > the
> > > > DROs
> > > > > update in significant increments, rather than the relatively smooth
> > > > updates
> > > > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec,
> > so
> > > I
> > > > > would expect it to appear smoother. Could still be problems in my
> > code,
> > > so
> > > > > none of this concerns me at all at this early stage of the game.
> > > > >
> > > > > However, in working on the problem of the mis-executing DSP threads,
> > > I've
> > > > > discovered something really odd. I tested the two programs in
> question
> > > > under
> > > > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> > > they
> > > > > both execute correctly first time, every time, without fail. But,
> run
> > > them
> > > > > under my app, using the few lines of code posted last night, and the
> > > > threads
> > > > > start, may, or may not, make the first move, then go out to lunch.
> > > KMotion
> > > > > confirms the threads remain running long after they should have
> > > > terminated,
> > > > > so they seem to be stuck waiting for..... something. Now, here's the
> > > > bizarre
> > > > > part - If I open KMotionCNC - I don't do anything else, just open
> the
> > > app
> > > > -
> > > > > the thread immediately picks up and runs to completion correctly! If
> I
> > > > just
> > > > > leave KMotionCNC running alongside my app, both DSP programs work
> > > > perfectly
> > > > > every time. In addition, one of them uses a MsgBox to give a message
> > to
> > > > the
> > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> MsgBox
> > > does
> > > > > not appear UNTIL KMotionCNC get focus, even though the DSP thread
> was
> > > > > launched from MY app!
> > > > >
> > > > > What is going on here? What is KMotionCNC doing that affects my DSP
> > > > programs
> > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when
> it
> > > did
> > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> that's
> > > > > filling up and blocking communications? I'm at a total loss here...
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3476 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I've got this working pretty well now, with a few exceptions. But I'm not clear on the right way to handle communications with dotNet. My UI update thread needs to access various dotNet data to create the updates. Right now, I'm doing those accesses in the DoWork method, creating an object that contains the UI status, then tossing that over to the UI thread to update the controls. But, the UI thread also needs to access dotNet when things like button events occur. Should I push ALL dotNet accesses to the UI thread? Or is there a better way?

Right now, something I've done has made the hangs much worse. I'm getting pretty regular hangs in the DLL, without disconnects, and also can't seem to get the BackgroundWorker thread to exit. It stops updating the display, but doesn't exit.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> Well, I moved the display updates to a BackgroundWorker thread by plagiarizing what you do in your HTML app. It was relatively painless, but, surprisingly, didn't really make any perceptible difference in terms of display update performance. It also, not surprisingly, introduced a couple of minor bugs. I have yet to get it to reliably close cleanly. On the FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I still sometimes get a null reference error in UpdateDocument when Dispose is called. Not sure I understand why that's happening.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> >
> > The only thing I will add at this point is try it and you will see.
> >
> >
> >
> >
> >
> > I will add that MM uses a multi-threading model, has a lot more rendering
> > going on that a winforms app, also does openGL toolpath display and I can
> > see out to 4-5 decimals changing smoothly during feed moves.
> >
> >
> >
> >
> >
> > Nowadays any non-trivial app requires multi-threading.
> >
> >
> >
> >
> >
> > -Brad
> >
> >
> >
> > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 8:59 PM
> > To: DynoMotion@yahoogroups.com
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > Here's where I keep getting stuck - I believe the bulk of the display update
> > time is getting the information from dotNet, not actually updating the
> > controls. I already update the DROs more often than the other controls, by
> > just doing the DROs on every timer tick, and the others on alternate ticks.
> > How will another thread improve performance, if the bottleneck is getting
> > the update data (which comes primarily from MainStatus), particularly since
> > I have to go through an invoke to modify each control?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > >
> > > First off, you never want to have too many threads running, technically
> > you
> > > can only have one run per core and anything after that is going to be time
> > > slicing.
> > >
> > >
> > >
> > >
> > >
> > > If I was making a small lightweight winforms app in .net3.5(like the HTML
> > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > earlier.
> > >
> > >
> > >
> > > Inside of it, I basically have an endless loop running on a separate
> > > worker thread using the simple BackgroundWorker class. The endless loop
> > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > Within
> > > the loop I also have a counter that I increment/reset every 5 cycles and
> > > when that happens I update the less important items.
> > >
> > >
> > >
> > > Very basic setup that only uses one additional thread that updates the
> > DRO's
> > > 1/10th a second and then things like LED's, enable status, etc… get
> > updated
> > > every ½ a second.
> > >
> > >
> > >
> > > I will re-upload my source so you can see how it works.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'm not changing to WPF at this late stage of the game! :-)
> > >
> > > I can see how I could use parallel threads to make the display updates
> > more
> > > efficient (launch separate threads to update all the DROs, and other
> > > controls). I assume the wonders of .NET will deal with all the concurrency
> > > issues that could create in accessing especially dotNet objects? I just
> > > checked and my update loop is running only about 5X/second right now,
> > though
> > > GUI response is generally not bad. It's mostly the DRO updates that really
> > > need to be sped up.
> > >
> > > How would you do it?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Absolutely, you can push from wherever, but you will need to pass a
> > > > reference to a control you are using(best bet is the main window) to
> > your
> > > > middle layer.
> > > >
> > > >
> > > >
> > > > If you used WPF you would not need to maintain a reference to any
> > control
> > > as
> > > > you could walk up the tree to the current Dispatcher.
> > > >
> > > >
> > > >
> > > > -Brad
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > Sorry - too many projects, too many people.... :-)
> > > >
> > > > I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> > > > high-level. All communications passes through that layer, and it also
> > > allows
> > > > me to pull dotNet out, and replace the gasket with a simulator, to test
> > > the
> > > > GUI stand-alone, and force all the possible states.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Who you calling Gary? ;)
> > > > >
> > > > >
> > > > >
> > > > > Clarify KM"gasket" please.
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Gary,
> > > > >
> > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > assume
> > > > that
> > > > > could be used to push GUI updates from my KM "gasket" when something
> > > > > changes, rather than pulling them from the main app, right?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > I would ditch the timer as well, using a service thread to interact
> > > with
> > > > > the
> > > > > > kflop will be much smoother.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Instead of running your updates via your timer's callback you can
> > > either
> > > > > use
> > > > > > the BackgroundWorker or an Async Delegate or parallel task if using
> > > > > .net4.0
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Parallel tasks are best because the will automagically load your cpu
> > > > usage
> > > > > > based on how many cores are available, etc.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Background workers are pretty easy to use and have a comprehensive
> > use
> > > > > > model.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy
> > to
> > > > use
> > > > > to
> > > > > > and easy to read.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Whichever method you use, you will need to Invoke/Dispatch your
> > > control
> > > > > > updates when using Winforms/WPF respectively.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > It looks like you are using winforms, so here is a quick
> > > pseudo-example
> > > > > > where I am using a common method that takes an Action as a parameter
> > > and
> > > > > > decides whether to invoke or not::
> > > > > >
> > > > > >
> > > > > >
> > > > > > public void UpdateDocument(Action action)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > > > coming from a thread other than the GUI
> > > > > >
> > > > > > {
> > > > > >
> > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > thread
> > > > > >
> > > > > > }
> > > > > >
> > > > > > else
> > > > > >
> > > > > > {
> > > > > >
> > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > invocation required
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > In the updating method of whichever threading model you chose, you
> > can
> > > > use
> > > > > > the above method like so::
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > UpdateDocument(new Action(delegate()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //Put your control updating code here.
> > > > > >
> > > > > > //Example:
> > > > > >
> > > > > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > > > > >
> > > > > > }));
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > So, I've been exercising my app on the machine, and for the most
> > > parts,
> > > > > > things are working OK, though it seems a bit "sluggish" to me. For
> > > > > example,
> > > > > > when I single-step, it takes a good 1/2 second or more to execute a
> > > line
> > > > > of
> > > > > > G-code containing nothing more than a single comment. When running,
> > > the
> > > > > DROs
> > > > > > update in significant increments, rather than the relatively smooth
> > > > > updates
> > > > > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec,
> > > so
> > > > I
> > > > > > would expect it to appear smoother. Could still be problems in my
> > > code,
> > > > so
> > > > > > none of this concerns me at all at this early stage of the game.
> > > > > >
> > > > > > However, in working on the problem of the mis-executing DSP threads,
> > > > I've
> > > > > > discovered something really odd. I tested the two programs in
> > question
> > > > > under
> > > > > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> > > > they
> > > > > > both execute correctly first time, every time, without fail. But,
> > run
> > > > them
> > > > > > under my app, using the few lines of code posted last night, and the
> > > > > threads
> > > > > > start, may, or may not, make the first move, then go out to lunch.
> > > > KMotion
> > > > > > confirms the threads remain running long after they should have
> > > > > terminated,
> > > > > > so they seem to be stuck waiting for..... something. Now, here's the
> > > > > bizarre
> > > > > > part - If I open KMotionCNC - I don't do anything else, just open
> > the
> > > > app
> > > > > -
> > > > > > the thread immediately picks up and runs to completion correctly! If
> > I
> > > > > just
> > > > > > leave KMotionCNC running alongside my app, both DSP programs work
> > > > > perfectly
> > > > > > every time. In addition, one of them uses a MsgBox to give a message
> > > to
> > > > > the
> > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > MsgBox
> > > > does
> > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP thread
> > was
> > > > > > launched from MY app!
> > > > > >
> > > > > > What is going on here? What is KMotionCNC doing that affects my DSP
> > > > > programs
> > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when
> > it
> > > > did
> > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > that's
> > > > > > filling up and blocking communications? I'm at a total loss here...
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3477 From: Brad Murry Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Hello Ray,

 

I would probably need to see some code to be much help.

 

Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Thursday, January 26, 2012 8:57 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

I've got this working pretty well now, with a few exceptions. But I'm not clear on the right way to handle communications with dotNet. My UI update thread needs to access various dotNet data to create the updates. Right now, I'm doing those accesses in the DoWork method, creating an object that contains the UI status, then tossing that over to the UI thread to update the controls. But, the UI thread also needs to access dotNet when things like button events occur. Should I push ALL dotNet accesses to the UI thread? Or is there a better way?

Right now, something I've done has made the hangs much worse. I'm getting pretty regular hangs in the DLL, without disconnects, and also can't seem to get the BackgroundWorker thread to exit. It stops updating the display, but doesn't exit.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> Well, I moved the display updates to a BackgroundWorker thread by plagiarizing what you do in your HTML app. It was relatively painless, but, surprisingly, didn't really make any perceptible difference in terms of display update performance. It also, not surprisingly, introduced a couple of minor bugs. I have yet to get it to reliably close cleanly. On the FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I still sometimes get a null reference error in UpdateDocument when Dispose is called. Not sure I understand why that's happening.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> >
> > The only thing I will add at this point is try it and you will see.
> >
> >
> >
> >
> >
> > I will add that MM uses a multi-threading model, has a lot more rendering
> > going on that a winforms app, also does openGL toolpath display and I can
> > see out to 4-5 decimals changing smoothly during feed moves.
> >
> >
> >
> >
> >
> > Nowadays any non-trivial app requires multi-threading.
> >
> >
> >
> >
> >
> > -Brad
> >
> >
> >
> > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > Behalf Of himykabibble
> > Sent: Wednesday, January 25, 2012 8:59 PM
> > To: DynoMotion@yahoogroups.com
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > Here's where I keep getting stuck - I believe the bulk of the display update
> > time is getting the information from dotNet, not actually updating the
> > controls. I already update the DROs more often than the other controls, by
> > just doing the DROs on every timer tick, and the others on alternate ticks.
> > How will another thread improve performance, if the bottleneck is getting
> > the update data (which comes primarily from MainStatus), particularly since
> > I have to go through an invoke to modify each control?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > >
> > > First off, you never want to have too many threads running, technically
> > you
> > > can only have one run per core and anything after that is going to be time
> > > slicing.
> > >
> > >
> > >
> > >
> > >
> > > If I was making a small lightweight winforms app in .net3.5(like the HTML
> > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > earlier.
> > >
> > >
> > >
> > > Inside of it, I basically have an endless loop running on a separate
> > > worker thread using the simple BackgroundWorker class. The endless loop
> > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > Within
> > > the loop I also have a counter that I increment/reset every 5 cycles and
> > > when that happens I update the less important items.
> > >
> > >
> > >
> > > Very basic setup that only uses one additional thread that updates the
> > DRO's
> > > 1/10th a second and then things like LED's, enable status, etc… get
> > updated
> > > every ½ a second.
> > >
> > >
> > >
> > > I will re-upload my source so you can see how it works.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'm not changing to WPF at this late stage of the game! :-)
> > >
> > > I can see how I could use parallel threads to make the display updates
> > more
> > > efficient (launch separate threads to update all the DROs, and other
> > > controls). I assume the wonders of .NET will deal with all the concurrency
> > > issues that could create in accessing especially dotNet objects? I just
> > > checked and my update loop is running only about 5X/second right now,
> > though
> > > GUI response is generally not bad. It's mostly the DRO updates that really
> > > need to be sped up.
> > >
> > > How would you do it?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Absolutely, you can push from wherever, but you will need to pass a
> > > > reference to a control you are using(best bet is the main window) to
> > your
> > > > middle layer.
> > > >
> > > >
> > > >
> > > > If you used WPF you would not need to maintain a reference to any
> > control
> > > as
> > > > you could walk up the tree to the current Dispatcher.
> > > >
> > > >
> > > >
> > > > -Brad
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > Sorry - too many projects, too many people.... :-)
> > > >
> > > > I have a layer between my GUI and dotNet, to keep the GUI "clean" and
> > > > high-level. All communications passes through that layer, and it also
> > > allows
> > > > me to pull dotNet out, and replace the gasket with a simulator, to test
> > > the
> > > > GUI stand-alone, and force all the possible states.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Who you calling Gary? ;)
> > > > >
> > > > >
> > > > >
> > > > > Clarify KM"gasket" please.
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Gary,
> > > > >
> > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > assume
> > > > that
> > > > > could be used to push GUI updates from my KM "gasket" when something
> > > > > changes, rather than pulling them from the main app, right?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > I would ditch the timer as well, using a service thread to interact
> > > with
> > > > > the
> > > > > > kflop will be much smoother.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Instead of running your updates via your timer's callback you can
> > > either
> > > > > use
> > > > > > the BackgroundWorker or an Async Delegate or parallel task if using
> > > > > .net4.0
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Parallel tasks are best because the will automagically load your cpu
> > > > usage
> > > > > > based on how many cores are available, etc.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Background workers are pretty easy to use and have a comprehensive
> > use
> > > > > > model.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are easy
> > to
> > > > use
> > > > > to
> > > > > > and easy to read.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Whichever method you use, you will need to Invoke/Dispatch your
> > > control
> > > > > > updates when using Winforms/WPF respectively.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > It looks like you are using winforms, so here is a quick
> > > pseudo-example
> > > > > > where I am using a common method that takes an Action as a parameter
> > > and
> > > > > > decides whether to invoke or not::
> > > > > >
> > > > > >
> > > > > >
> > > > > > public void UpdateDocument(Action action)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > > > coming from a thread other than the GUI
> > > > > >
> > > > > > {
> > > > > >
> > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > thread
> > > > > >
> > > > > > }
> > > > > >
> > > > > > else
> > > > > >
> > > > > > {
> > > > > >
> > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > invocation required
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > In the updating method of whichever threading model you chose, you
> > can
> > > > use
> > > > > > the above method like so::
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > UpdateDocument(new Action(delegate()
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //Put your control updating code here.
> > > > > >
> > > > > > //Example:
> > > > > >
> > > > > > lblXaxisDest.Text = _AxisContainer["X"].ActualPosition.ToString();
> > > > > >
> > > > > > }));
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > So, I've been exercising my app on the machine, and for the most
> > > parts,
> > > > > > things are working OK, though it seems a bit "sluggish" to me. For
> > > > > example,
> > > > > > when I single-step, it takes a good 1/2 second or more to execute a
> > > line
> > > > > of
> > > > > > G-code containing nothing more than a single comment. When running,
> > > the
> > > > > DROs
> > > > > > update in significant increments, rather than the relatively smooth
> > > > > updates
> > > > > > I'm accustomed to with Mach3. I'm polling status at roughly 100mSec,
> > > so
> > > > I
> > > > > > would expect it to appear smoother. Could still be problems in my
> > > code,
> > > > so
> > > > > > none of this concerns me at all at this early stage of the game.
> > > > > >
> > > > > > However, in working on the problem of the mis-executing DSP threads,
> > > > I've
> > > > > > discovered something really odd. I tested the two programs in
> > question
> > > > > under
> > > > > > KMotionCNC, and am satisfied the code is correct - Under KMotionCNC,
> > > > they
> > > > > > both execute correctly first time, every time, without fail. But,
> > run
> > > > them
> > > > > > under my app, using the few lines of code posted last night, and the
> > > > > threads
> > > > > > start, may, or may not, make the first move, then go out to lunch.
> > > > KMotion
> > > > > > confirms the threads remain running long after they should have
> > > > > terminated,
> > > > > > so they seem to be stuck waiting for..... something. Now, here's the
> > > > > bizarre
> > > > > > part - If I open KMotionCNC - I don't do anything else, just open
> > the
> > > > app
> > > > > -
> > > > > > the thread immediately picks up and runs to completion correctly! If
> > I
> > > > > just
> > > > > > leave KMotionCNC running alongside my app, both DSP programs work
> > > > > perfectly
> > > > > > every time. In addition, one of them uses a MsgBox to give a message
> > > to
> > > > > the
> > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > MsgBox
> > > > does
> > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP thread
> > was
> > > > > > launched from MY app!
> > > > > >
> > > > > > What is going on here? What is KMotionCNC doing that affects my DSP
> > > > > programs
> > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC, when
> > it
> > > > did
> > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > that's
> > > > > > filling up and blocking communications? I'm at a total loss here...
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > >
> > > >
> > >
> >
>

Group: DynoMotion Message: 3478 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I'd be happy to send you my code, if you promise not to laugh too hard.... But perhaps a simple example:

My BackgroundWorker Thread needs to do UpdateStatus, and read things like current tool, spindle RPM, and a number of other things. Those are currently be done in the BackgroundWorker thread by direct calls to my KM_Controller.

Some of the Button Click handlers also need to access things in KM_Controller. For example, the SpindleCW button needs to set two I/Os, and run a DSP program to set the PWM. For this, the ButtonClick handler calls a method in my dotNet "gasket" that handles all this.

So, My KM_Controller is currently getting called by both the UI thread, and the BackgroundWorker thread, which I assume is not a good idea. Would it not be better to have only one thread talking the KM_Controller? If so, should I move all calls from the BackgroundWorker thread to the UI thread, or vice-versa. Or perhaps there's another/better option?

I looked through your HTML app code, but you don't seem to be dealing with that problem yet, since it appears to me only the DROs are actually functional, and their operation is straight-forward (though I note you are making calls directly to dotrNet from the BackgroundWorker DoWork method).

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Hello Ray,
>
>
>
> I would probably need to see some code to be much help.
>
>
>
> Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Thursday, January 26, 2012 8:57 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> I've got this working pretty well now, with a few exceptions. But I'm not
> clear on the right way to handle communications with dotNet. My UI update
> thread needs to access various dotNet data to create the updates. Right now,
> I'm doing those accesses in the DoWork method, creating an object that
> contains the UI status, then tossing that over to the UI thread to update
> the controls. But, the UI thread also needs to access dotNet when things
> like button events occur. Should I push ALL dotNet accesses to the UI
> thread? Or is there a better way?
>
> Right now, something I've done has made the hangs much worse. I'm getting
> pretty regular hangs in the DLL, without disconnects, and also can't seem to
> get the BackgroundWorker thread to exit. It stops updating the display, but
> doesn't exit.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Well, I moved the display updates to a BackgroundWorker thread by
> plagiarizing what you do in your HTML app. It was relatively painless, but,
> surprisingly, didn't really make any perceptible difference in terms of
> display update performance. It also, not surprisingly, introduced a couple
> of minor bugs. I have yet to get it to reliably close cleanly. On the
> FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I still
> sometimes get a null reference error in UpdateDocument when Dispose is
> called. Not sure I understand why that's happening.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> > >
> > > The only thing I will add at this point is try it and you will see.
> > >
> > >
> > >
> > >
> > >
> > > I will add that MM uses a multi-threading model, has a lot more
> rendering
> > > going on that a winforms app, also does openGL toolpath display and I
> can
> > > see out to 4-5 decimals changing smoothly during feed moves.
> > >
> > >
> > >
> > >
> > >
> > > Nowadays any non-trivial app requires multi-threading.
> > >
> > >
> > >
> > >
> > >
> > > -Brad
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > Here's where I keep getting stuck - I believe the bulk of the display
> update
> > > time is getting the information from dotNet, not actually updating the
> > > controls. I already update the DROs more often than the other controls,
> by
> > > just doing the DROs on every timer tick, and the others on alternate
> ticks.
> > > How will another thread improve performance, if the bottleneck is
> getting
> > > the update data (which comes primarily from MainStatus), particularly
> since
> > > I have to go through an invoke to modify each control?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > >
> > > > First off, you never want to have too many threads running,
> technically
> > > you
> > > > can only have one run per core and anything after that is going to be
> time
> > > > slicing.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > If I was making a small lightweight winforms app in .net3.5(like the
> HTML
> > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > earlier.
> > > >
> > > >
> > > >
> > > > Inside of it, I basically have an endless loop running on a separate
> > > > worker thread using the simple BackgroundWorker class. The endless
> loop
> > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > Within
> > > > the loop I also have a counter that I increment/reset every 5 cycles
> and
> > > > when that happens I update the less important items.
> > > >
> > > >
> > > >
> > > > Very basic setup that only uses one additional thread that updates the
> > > DRO's
> > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > updated
> > > > every ½ a second.
> > > >
> > > >
> > > >
> > > > I will re-upload my source so you can see how it works.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I'm not changing to WPF at this late stage of the game! :-)
> > > >
> > > > I can see how I could use parallel threads to make the display updates
> > > more
> > > > efficient (launch separate threads to update all the DROs, and other
> > > > controls). I assume the wonders of .NET will deal with all the
> concurrency
> > > > issues that could create in accessing especially dotNet objects? I
> just
> > > > checked and my update loop is running only about 5X/second right now,
> > > though
> > > > GUI response is generally not bad. It's mostly the DRO updates that
> really
> > > > need to be sped up.
> > > >
> > > > How would you do it?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Absolutely, you can push from wherever, but you will need to pass a
> > > > > reference to a control you are using(best bet is the main window) to
> > > your
> > > > > middle layer.
> > > > >
> > > > >
> > > > >
> > > > > If you used WPF you would not need to maintain a reference to any
> > > control
> > > > as
> > > > > you could walk up the tree to the current Dispatcher.
> > > > >
> > > > >
> > > > >
> > > > > -Brad
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > Sorry - too many projects, too many people.... :-)
> > > > >
> > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> and
> > > > > high-level. All communications passes through that layer, and it
> also
> > > > allows
> > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> test
> > > > the
> > > > > GUI stand-alone, and force all the possible states.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Who you calling Gary? ;)
> > > > > >
> > > > > >
> > > > > >
> > > > > > Clarify KM"gasket" please.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Gary,
> > > > > >
> > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > assume
> > > > > that
> > > > > > could be used to push GUI updates from my KM "gasket" when
> something
> > > > > > changes, rather than pulling them from the main app, right?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I would ditch the timer as well, using a service thread to
> interact
> > > > with
> > > > > > the
> > > > > > > kflop will be much smoother.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Instead of running your updates via your timer's callback you
> can
> > > > either
> > > > > > use
> > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> using
> > > > > > .net4.0
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Parallel tasks are best because the will automagically load your
> cpu
> > > > > usage
> > > > > > > based on how many cores are available, etc.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Background workers are pretty easy to use and have a
> comprehensive
> > > use
> > > > > > > model.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> easy
> > > to
> > > > > use
> > > > > > to
> > > > > > > and easy to read.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Whichever method you use, you will need to Invoke/Dispatch your
> > > > control
> > > > > > > updates when using Winforms/WPF respectively.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > It looks like you are using winforms, so here is a quick
> > > > pseudo-example
> > > > > > > where I am using a common method that takes an Action as a
> parameter
> > > > and
> > > > > > > decides whether to invoke or not::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > public void UpdateDocument(Action action)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > > > > coming from a thread other than the GUI
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > thread
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > else
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > invocation required
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > In the updating method of whichever threading model you chose,
> you
> > > can
> > > > > use
> > > > > > > the above method like so::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > UpdateDocument(new Action(delegate()
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Put your control updating code here.
> > > > > > >
> > > > > > > //Example:
> > > > > > >
> > > > > > > lblXaxisDest.Text =
> _AxisContainer["X"].ActualPosition.ToString();
> > > > > > >
> > > > > > > }));
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > So, I've been exercising my app on the machine, and for the most
> > > > parts,
> > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> For
> > > > > > example,
> > > > > > > when I single-step, it takes a good 1/2 second or more to
> execute a
> > > > line
> > > > > > of
> > > > > > > G-code containing nothing more than a single comment. When
> running,
> > > > the
> > > > > > DROs
> > > > > > > update in significant increments, rather than the relatively
> smooth
> > > > > > updates
> > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> 100mSec,
> > > > so
> > > > > I
> > > > > > > would expect it to appear smoother. Could still be problems in
> my
> > > > code,
> > > > > so
> > > > > > > none of this concerns me at all at this early stage of the game.
> > > > > > >
> > > > > > > However, in working on the problem of the mis-executing DSP
> threads,
> > > > > I've
> > > > > > > discovered something really odd. I tested the two programs in
> > > question
> > > > > > under
> > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> KMotionCNC,
> > > > > they
> > > > > > > both execute correctly first time, every time, without fail.
> But,
> > > run
> > > > > them
> > > > > > > under my app, using the few lines of code posted last night, and
> the
> > > > > > threads
> > > > > > > start, may, or may not, make the first move, then go out to
> lunch.
> > > > > KMotion
> > > > > > > confirms the threads remain running long after they should have
> > > > > > terminated,
> > > > > > > so they seem to be stuck waiting for..... something. Now, here's
> the
> > > > > > bizarre
> > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> open
> > > the
> > > > > app
> > > > > > -
> > > > > > > the thread immediately picks up and runs to completion
> correctly! If
> > > I
> > > > > > just
> > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> work
> > > > > > perfectly
> > > > > > > every time. In addition, one of them uses a MsgBox to give a
> message
> > > > to
> > > > > > the
> > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > MsgBox
> > > > > does
> > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> thread
> > > was
> > > > > > > launched from MY app!
> > > > > > >
> > > > > > > What is going on here? What is KMotionCNC doing that affects my
> DSP
> > > > > > programs
> > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> when
> > > it
> > > > > did
> > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > that's
> > > > > > > filling up and blocking communications? I'm at a total loss
> here...
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3480 From: Brad Murry Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Ray,

 

As far as your code goes, I would be looking with an non-judgmental eye and with the only goal of finding your problem.

 

 

Before that , you could try to surround any calls to the KM_Controller instance with a lock clause.  This will allow only one thread  at a time to access the controller object.

 

Example::

 

lock(_Controller)

{

var status = _Controller.WriteLineReadLine(“Version”);

 

var status2 = _Controller.WriteLineReadLine(“Version”);

}

 

Basically, any function you are using the KM_Controller instance in may need to be placed in a lock.

 

Example2::

 

Public void MyUpdatingOrCommandingFunction(args….)

{

lock(_Controller)

{

//Do stuff with your controller here

}

}

 

 

Try this and let me know if it helps.  It is making sense to me that the KM_Controller is not Thread safe as it is maintaining pointer references….  I never ran into it on MM as it never accesses the GUI thread.

 

-Brad Murry

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Thursday, January 26, 2012 9:14 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

I'd be happy to send you my code, if you promise not to laugh too hard.... But perhaps a simple example:

My BackgroundWorker Thread needs to do UpdateStatus, and read things like current tool, spindle RPM, and a number of other things. Those are currently be done in the BackgroundWorker thread by direct calls to my KM_Controller.

Some of the Button Click handlers also need to access things in KM_Controller. For example, the SpindleCW button needs to set two I/Os, and run a DSP program to set the PWM. For this, the ButtonClick handler calls a method in my dotNet "gasket" that handles all this.

So, My KM_Controller is currently getting called by both the UI thread, and the BackgroundWorker thread, which I assume is not a good idea. Would it not be better to have only one thread talking the KM_Controller? If so, should I move all calls from the BackgroundWorker thread to the UI thread, or vice-versa. Or perhaps there's another/better option?

I looked through your HTML app code, but you don't seem to be dealing with that problem yet, since it appears to me only the DROs are actually functional, and their operation is straight-forward (though I note you are making calls directly to dotrNet from the BackgroundWorker DoWork method).

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Hello Ray,
>
>
>
> I would probably need to see some code to be much help.
>
>
>
> Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Thursday, January 26, 2012 8:57 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> I've got this working pretty well now, with a few exceptions. But I'm not
> clear on the right way to handle communications with dotNet. My UI update
> thread needs to access various dotNet data to create the updates. Right now,
> I'm doing those accesses in the DoWork method, creating an object that
> contains the UI status, then tossing that over to the UI thread to update
> the controls. But, the UI thread also needs to access dotNet when things
> like button events occur. Should I push ALL dotNet accesses to the UI
> thread? Or is there a better way?
>
> Right now, something I've done has made the hangs much worse. I'm getting
> pretty regular hangs in the DLL, without disconnects, and also can't seem to
> get the BackgroundWorker thread to exit. It stops updating the display, but
> doesn't exit.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Well, I moved the display updates to a BackgroundWorker thread by
> plagiarizing what you do in your HTML app. It was relatively painless, but,
> surprisingly, didn't really make any perceptible difference in terms of
> display update performance. It also, not surprisingly, introduced a couple
> of minor bugs. I have yet to get it to reliably close cleanly. On the
> FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I still
> sometimes get a null reference error in UpdateDocument when Dispose is
> called. Not sure I understand why that's happening.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> > >
> > > The only thing I will add at this point is try it and you will see.
> > >
> > >
> > >
> > >
> > >
> > > I will add that MM uses a multi-threading model, has a lot more
> rendering
> > > going on that a winforms app, also does openGL toolpath display and I
> can
> > > see out to 4-5 decimals changing smoothly during feed moves.
> > >
> > >
> > >
> > >
> > >
> > > Nowadays any non-trivial app requires multi-threading.
> > >
> > >
> > >
> > >
> > >
> > > -Brad
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > > Behalf Of himykabibble
> > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > Here's where I keep getting stuck - I believe the bulk of the display
> update
> > > time is getting the information from dotNet, not actually updating the
> > > controls. I already update the DROs more often than the other controls,
> by
> > > just doing the DROs on every timer tick, and the others on alternate
> ticks.
> > > How will another thread improve performance, if the bottleneck is
> getting
> > > the update data (which comes primarily from MainStatus), particularly
> since
> > > I have to go through an invoke to modify each control?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > >
> > > > First off, you never want to have too many threads running,
> technically
> > > you
> > > > can only have one run per core and anything after that is going to be
> time
> > > > slicing.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > If I was making a small lightweight winforms app in .net3.5(like the
> HTML
> > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > earlier.
> > > >
> > > >
> > > >
> > > > Inside of it, I basically have an endless loop running on a separate
> > > > worker thread using the simple BackgroundWorker class. The endless
> loop
> > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > Within
> > > > the loop I also have a counter that I increment/reset every 5 cycles
> and
> > > > when that happens I update the less important items.
> > > >
> > > >
> > > >
> > > > Very basic setup that only uses one additional thread that updates the
> > > DRO's
> > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > updated
> > > > every ½ a second.
> > > >
> > > >
> > > >
> > > > I will re-upload my source so you can see how it works.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I'm not changing to WPF at this late stage of the game! :-)
> > > >
> > > > I can see how I could use parallel threads to make the display updates
> > > more
> > > > efficient (launch separate threads to update all the DROs, and other
> > > > controls). I assume the wonders of .NET will deal with all the
> concurrency
> > > > issues that could create in accessing especially dotNet objects? I
> just
> > > > checked and my update loop is running only about 5X/second right now,
> > > though
> > > > GUI response is generally not bad. It's mostly the DRO updates that
> really
> > > > need to be sped up.
> > > >
> > > > How would you do it?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Absolutely, you can push from wherever, but you will need to pass a
> > > > > reference to a control you are using(best bet is the main window) to
> > > your
> > > > > middle layer.
> > > > >
> > > > >
> > > > >
> > > > > If you used WPF you would not need to maintain a reference to any
> > > control
> > > > as
> > > > > you could walk up the tree to the current Dispatcher.
> > > > >
> > > > >
> > > > >
> > > > > -Brad
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > Sorry - too many projects, too many people.... :-)
> > > > >
> > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> and
> > > > > high-level. All communications passes through that layer, and it
> also
> > > > allows
> > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> test
> > > > the
> > > > > GUI stand-alone, and force all the possible states.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Who you calling Gary? ;)
> > > > > >
> > > > > >
> > > > > >
> > > > > > Clarify KM"gasket" please.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Gary,
> > > > > >
> > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > assume
> > > > > that
> > > > > > could be used to push GUI updates from my KM "gasket" when
> something
> > > > > > changes, rather than pulling them from the main app, right?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I would ditch the timer as well, using a service thread to
> interact
> > > > with
> > > > > > the
> > > > > > > kflop will be much smoother.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Instead of running your updates via your timer's callback you
> can
> > > > either
> > > > > > use
> > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> using
> > > > > > .net4.0
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Parallel tasks are best because the will automagically load your
> cpu
> > > > > usage
> > > > > > > based on how many cores are available, etc.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Background workers are pretty easy to use and have a
> comprehensive
> > > use
> > > > > > > model.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> easy
> > > to
> > > > > use
> > > > > > to
> > > > > > > and easy to read.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Whichever method you use, you will need to Invoke/Dispatch your
> > > > control
> > > > > > > updates when using Winforms/WPF respectively.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > It looks like you are using winforms, so here is a quick
> > > > pseudo-example
> > > > > > > where I am using a common method that takes an Action as a
> parameter
> > > > and
> > > > > > > decides whether to invoke or not::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > public void UpdateDocument(Action action)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call is
> > > > > > > coming from a thread other than the GUI
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > thread
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > else
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > invocation required
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > In the updating method of whichever threading model you chose,
> you
> > > can
> > > > > use
> > > > > > > the above method like so::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > UpdateDocument(new Action(delegate()
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Put your control updating code here.
> > > > > > >
> > > > > > > //Example:
> > > > > > >
> > > > > > > lblXaxisDest.Text =
> _AxisContainer["X"].ActualPosition.ToString();
> > > > > > >
> > > > > > > }));
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > So, I've been exercising my app on the machine, and for the most
> > > > parts,
> > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> For
> > > > > > example,
> > > > > > > when I single-step, it takes a good 1/2 second or more to
> execute a
> > > > line
> > > > > > of
> > > > > > > G-code containing nothing more than a single comment. When
> running,
> > > > the
> > > > > > DROs
> > > > > > > update in significant increments, rather than the relatively
> smooth
> > > > > > updates
> > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> 100mSec,
> > > > so
> > > > > I
> > > > > > > would expect it to appear smoother. Could still be problems in
> my
> > > > code,
> > > > > so
> > > > > > > none of this concerns me at all at this early stage of the game.
> > > > > > >
> > > > > > > However, in working on the problem of the mis-executing DSP
> threads,
> > > > > I've
> > > > > > > discovered something really odd. I tested the two programs in
> > > question
> > > > > > under
> > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> KMotionCNC,
> > > > > they
> > > > > > > both execute correctly first time, every time, without fail.
> But,
> > > run
> > > > > them
> > > > > > > under my app, using the few lines of code posted last night, and
> the
> > > > > > threads
> > > > > > > start, may, or may not, make the first move, then go out to
> lunch.
> > > > > KMotion
> > > > > > > confirms the threads remain running long after they should have
> > > > > > terminated,
> > > > > > > so they seem to be stuck waiting for..... something. Now, here's
> the
> > > > > > bizarre
> > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> open
> > > the
> > > > > app
> > > > > > -
> > > > > > > the thread immediately picks up and runs to completion
> correctly! If
> > > I
> > > > > > just
> > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> work
> > > > > > perfectly
> > > > > > > every time. In addition, one of them uses a MsgBox to give a
> message
> > > > to
> > > > > > the
> > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > MsgBox
> > > > > does
> > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> thread
> > > was
> > > > > > > launched from MY app!
> > > > > > >
> > > > > > > What is going on here? What is KMotionCNC doing that affects my
> DSP
> > > > > > programs
> > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> when
> > > it
> > > > > did
> > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > that's
> > > > > > > filling up and blocking communications? I'm at a total loss
> here...
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Group: DynoMotion Message: 3481 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?

"I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?

Regards,
Ray L.


--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Ray,
>
>
>
> As far as your code goes, I would be looking with an non-judgmental eye and
> with the only goal of finding your problem.
>
>
>
>
>
> Before that , you could try to surround any calls to the KM_Controller
> instance with a lock clause. This will allow only one thread at a time to
> access the controller object.
>
>
>
> Example::
>
>
>
> lock(_Controller)
>
> {
>
> var status = _Controller.WriteLineReadLine("Version");
>
>
>
> var status2 = _Controller.WriteLineReadLine("Version");
>
> }
>
>
>
> Basically, any function you are using the KM_Controller instance in may need
> to be placed in a lock.
>
>
>
> Example2::
>
>
>
> Public void MyUpdatingOrCommandingFunction(args….)
>
> {
>
> lock(_Controller)
>
> {
>
> //Do stuff with your controller here
>
> }
>
> }
>
>
>
>
>
> Try this and let me know if it helps. It is making sense to me that the
> KM_Controller is not Thread safe as it is maintaining pointer references….
> I never ran into it on MM as it never accesses the GUI thread.
>
>
>
> -Brad Murry
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> Behalf Of himykabibble
> Sent: Thursday, January 26, 2012 9:14 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> I'd be happy to send you my code, if you promise not to laugh too hard....
> But perhaps a simple example:
>
> My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> current tool, spindle RPM, and a number of other things. Those are currently
> be done in the BackgroundWorker thread by direct calls to my KM_Controller.
>
> Some of the Button Click handlers also need to access things in
> KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> method in my dotNet "gasket" that handles all this.
>
> So, My KM_Controller is currently getting called by both the UI thread, and
> the BackgroundWorker thread, which I assume is not a good idea. Would it not
> be better to have only one thread talking the KM_Controller? If so, should I
> move all calls from the BackgroundWorker thread to the UI thread, or
> vice-versa. Or perhaps there's another/better option?
>
> I looked through your HTML app code, but you don't seem to be dealing with
> that problem yet, since it appears to me only the DROs are actually
> functional, and their operation is straight-forward (though I note you are
> making calls directly to dotrNet from the BackgroundWorker DoWork method).
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> Brad Murry <bradodarb@> wrote:
> >
> > Hello Ray,
> >
> >
> >
> > I would probably need to see some code to be much help.
> >
> >
> >
> > Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> On
> > Behalf Of himykabibble
> > Sent: Thursday, January 26, 2012 8:57 PM
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > I've got this working pretty well now, with a few exceptions. But I'm not
> > clear on the right way to handle communications with dotNet. My UI update
> > thread needs to access various dotNet data to create the updates. Right
> now,
> > I'm doing those accesses in the DoWork method, creating an object that
> > contains the UI status, then tossing that over to the UI thread to update
> > the controls. But, the UI thread also needs to access dotNet when things
> > like button events occur. Should I push ALL dotNet accesses to the UI
> > thread? Or is there a better way?
> >
> > Right now, something I've done has made the hangs much worse. I'm getting
> > pretty regular hangs in the DLL, without disconnects, and also can't seem
> to
> > get the BackgroundWorker thread to exit. It stops updating the display,
> but
> > doesn't exit.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > Well, I moved the display updates to a BackgroundWorker thread by
> > plagiarizing what you do in your HTML app. It was relatively painless,
> but,
> > surprisingly, didn't really make any perceptible difference in terms of
> > display update performance. It also, not surprisingly, introduced a couple
> > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> still
> > sometimes get a null reference error in UpdateDocument when Dispose is
> > called. Not sure I understand why that's happening.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > > >
> > > > The only thing I will add at this point is try it and you will see.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > I will add that MM uses a multi-threading model, has a lot more
> > rendering
> > > > going on that a winforms app, also does openGL toolpath display and I
> > can
> > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Nowadays any non-trivial app requires multi-threading.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > -Brad
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > > Behalf Of himykabibble
> > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > Here's where I keep getting stuck - I believe the bulk of the display
> > update
> > > > time is getting the information from dotNet, not actually updating the
> > > > controls. I already update the DROs more often than the other
> controls,
> > by
> > > > just doing the DROs on every timer tick, and the others on alternate
> > ticks.
> > > > How will another thread improve performance, if the bottleneck is
> > getting
> > > > the update data (which comes primarily from MainStatus), particularly
> > since
> > > > I have to go through an invoke to modify each control?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > >
> > > > > First off, you never want to have too many threads running,
> > technically
> > > > you
> > > > > can only have one run per core and anything after that is going to
> be
> > time
> > > > > slicing.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > HTML
> > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > earlier.
> > > > >
> > > > >
> > > > >
> > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > worker thread using the simple BackgroundWorker class. The endless
> > loop
> > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > Within
> > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > and
> > > > > when that happens I update the less important items.
> > > > >
> > > > >
> > > > >
> > > > > Very basic setup that only uses one additional thread that updates
> the
> > > > DRO's
> > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > updated
> > > > > every ½ a second.
> > > > >
> > > > >
> > > > >
> > > > > I will re-upload my source so you can see how it works.
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > >
> > > > > I can see how I could use parallel threads to make the display
> updates
> > > > more
> > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > controls). I assume the wonders of .NET will deal with all the
> > concurrency
> > > > > issues that could create in accessing especially dotNet objects? I
> > just
> > > > > checked and my update loop is running only about 5X/second right
> now,
> > > > though
> > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > really
> > > > > need to be sped up.
> > > > >
> > > > > How would you do it?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Absolutely, you can push from wherever, but you will need to pass
> a
> > > > > > reference to a control you are using(best bet is the main window)
> to
> > > > your
> > > > > > middle layer.
> > > > > >
> > > > > >
> > > > > >
> > > > > > If you used WPF you would not need to maintain a reference to any
> > > > control
> > > > > as
> > > > > > you could walk up the tree to the current Dispatcher.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Sorry - too many projects, too many people.... :-)
> > > > > >
> > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > and
> > > > > > high-level. All communications passes through that layer, and it
> > also
> > > > > allows
> > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > test
> > > > > the
> > > > > > GUI stand-alone, and force all the possible states.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Who you calling Gary? ;)
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Clarify KM"gasket" please.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Gary,
> > > > > > >
> > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > assume
> > > > > > that
> > > > > > > could be used to push GUI updates from my KM "gasket" when
> > something
> > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I would ditch the timer as well, using a service thread to
> > interact
> > > > > with
> > > > > > > the
> > > > > > > > kflop will be much smoother.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Instead of running your updates via your timer's callback you
> > can
> > > > > either
> > > > > > > use
> > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > using
> > > > > > > .net4.0
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Parallel tasks are best because the will automagically load
> your
> > cpu
> > > > > > usage
> > > > > > > > based on how many cores are available, etc.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Background workers are pretty easy to use and have a
> > comprehensive
> > > > use
> > > > > > > > model.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > easy
> > > > to
> > > > > > use
> > > > > > > to
> > > > > > > > and easy to read.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> your
> > > > > control
> > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > pseudo-example
> > > > > > > > where I am using a common method that takes an Action as a
> > parameter
> > > > > and
> > > > > > > > decides whether to invoke or not::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > public void UpdateDocument(Action action)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> is
> > > > > > > > coming from a thread other than the GUI
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > thread
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > else
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > invocation required
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > In the updating method of whichever threading model you chose,
> > you
> > > > can
> > > > > > use
> > > > > > > > the above method like so::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > //Put your control updating code here.
> > > > > > > >
> > > > > > > > //Example:
> > > > > > > >
> > > > > > > > lblXaxisDest.Text =
> > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > >
> > > > > > > > }));
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > So, I've been exercising my app on the machine, and for the
> most
> > > > > parts,
> > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > For
> > > > > > > example,
> > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > execute a
> > > > > line
> > > > > > > of
> > > > > > > > G-code containing nothing more than a single comment. When
> > running,
> > > > > the
> > > > > > > DROs
> > > > > > > > update in significant increments, rather than the relatively
> > smooth
> > > > > > > updates
> > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > 100mSec,
> > > > > so
> > > > > > I
> > > > > > > > would expect it to appear smoother. Could still be problems in
> > my
> > > > > code,
> > > > > > so
> > > > > > > > none of this concerns me at all at this early stage of the
> game.
> > > > > > > >
> > > > > > > > However, in working on the problem of the mis-executing DSP
> > threads,
> > > > > > I've
> > > > > > > > discovered something really odd. I tested the two programs in
> > > > question
> > > > > > > under
> > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > KMotionCNC,
> > > > > > they
> > > > > > > > both execute correctly first time, every time, without fail.
> > But,
> > > > run
> > > > > > them
> > > > > > > > under my app, using the few lines of code posted last night,
> and
> > the
> > > > > > > threads
> > > > > > > > start, may, or may not, make the first move, then go out to
> > lunch.
> > > > > > KMotion
> > > > > > > > confirms the threads remain running long after they should
> have
> > > > > > > terminated,
> > > > > > > > so they seem to be stuck waiting for..... something. Now,
> here's
> > the
> > > > > > > bizarre
> > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > open
> > > > the
> > > > > > app
> > > > > > > -
> > > > > > > > the thread immediately picks up and runs to completion
> > correctly! If
> > > > I
> > > > > > > just
> > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > work
> > > > > > > perfectly
> > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > message
> > > > > to
> > > > > > > the
> > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > MsgBox
> > > > > > does
> > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > thread
> > > > was
> > > > > > > > launched from MY app!
> > > > > > > >
> > > > > > > > What is going on here? What is KMotionCNC doing that affects
> my
> > DSP
> > > > > > > programs
> > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > when
> > > > it
> > > > > > did
> > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > that's
> > > > > > > > filling up and blocking communications? I'm at a total loss
> > here...
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3483 From: bradodarb Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hello Ray,

Yes, lock every call.


MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.

looking forward to hearing back your results.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
>
> "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
>
> Regards,
> Ray L.
>
>
> --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> >
> > As far as your code goes, I would be looking with an non-judgmental eye and
> > with the only goal of finding your problem.
> >
> >
> >
> >
> >
> > Before that , you could try to surround any calls to the KM_Controller
> > instance with a lock clause. This will allow only one thread at a time to
> > access the controller object.
> >
> >
> >
> > Example::
> >
> >
> >
> > lock(_Controller)
> >
> > {
> >
> > var status = _Controller.WriteLineReadLine("Version");
> >
> >
> >
> > var status2 = _Controller.WriteLineReadLine("Version");
> >
> > }
> >
> >
> >
> > Basically, any function you are using the KM_Controller instance in may need
> > to be placed in a lock.
> >
> >
> >
> > Example2::
> >
> >
> >
> > Public void MyUpdatingOrCommandingFunction(args….)
> >
> > {
> >
> > lock(_Controller)
> >
> > {
> >
> > //Do stuff with your controller here
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > Try this and let me know if it helps. It is making sense to me that the
> > KM_Controller is not Thread safe as it is maintaining pointer references….
> > I never ran into it on MM as it never accesses the GUI thread.
> >
> >
> >
> > -Brad Murry
> >
> > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > Behalf Of himykabibble
> > Sent: Thursday, January 26, 2012 9:14 PM
> > To: DynoMotion@yahoogroups.com
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > I'd be happy to send you my code, if you promise not to laugh too hard....
> > But perhaps a simple example:
> >
> > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > current tool, spindle RPM, and a number of other things. Those are currently
> > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> >
> > Some of the Button Click handlers also need to access things in
> > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > method in my dotNet "gasket" that handles all this.
> >
> > So, My KM_Controller is currently getting called by both the UI thread, and
> > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > be better to have only one thread talking the KM_Controller? If so, should I
> > move all calls from the BackgroundWorker thread to the UI thread, or
> > vice-versa. Or perhaps there's another/better option?
> >
> > I looked through your HTML app code, but you don't seem to be dealing with
> > that problem yet, since it appears to me only the DROs are actually
> > functional, and their operation is straight-forward (though I note you are
> > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Hello Ray,
> > >
> > >
> > >
> > > I would probably need to see some code to be much help.
> > >
> > >
> > >
> > > Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 8:57 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > clear on the right way to handle communications with dotNet. My UI update
> > > thread needs to access various dotNet data to create the updates. Right
> > now,
> > > I'm doing those accesses in the DoWork method, creating an object that
> > > contains the UI status, then tossing that over to the UI thread to update
> > > the controls. But, the UI thread also needs to access dotNet when things
> > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > thread? Or is there a better way?
> > >
> > > Right now, something I've done has made the hangs much worse. I'm getting
> > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > to
> > > get the BackgroundWorker thread to exit. It stops updating the display,
> > but
> > > doesn't exit.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > plagiarizing what you do in your HTML app. It was relatively painless,
> > but,
> > > surprisingly, didn't really make any perceptible difference in terms of
> > > display update performance. It also, not surprisingly, introduced a couple
> > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > still
> > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > called. Not sure I understand why that's happening.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > The only thing I will add at this point is try it and you will see.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > I will add that MM uses a multi-threading model, has a lot more
> > > rendering
> > > > > going on that a winforms app, also does openGL toolpath display and I
> > > can
> > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Nowadays any non-trivial app requires multi-threading.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -Brad
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > update
> > > > > time is getting the information from dotNet, not actually updating the
> > > > > controls. I already update the DROs more often than the other
> > controls,
> > > by
> > > > > just doing the DROs on every timer tick, and the others on alternate
> > > ticks.
> > > > > How will another thread improve performance, if the bottleneck is
> > > getting
> > > > > the update data (which comes primarily from MainStatus), particularly
> > > since
> > > > > I have to go through an invoke to modify each control?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > >
> > > > > > First off, you never want to have too many threads running,
> > > technically
> > > > > you
> > > > > > can only have one run per core and anything after that is going to
> > be
> > > time
> > > > > > slicing.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > HTML
> > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > earlier.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > loop
> > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > Within
> > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > and
> > > > > > when that happens I update the less important items.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Very basic setup that only uses one additional thread that updates
> > the
> > > > > DRO's
> > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > updated
> > > > > > every ½ a second.
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will re-upload my source so you can see how it works.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > >
> > > > > > I can see how I could use parallel threads to make the display
> > updates
> > > > > more
> > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > controls). I assume the wonders of .NET will deal with all the
> > > concurrency
> > > > > > issues that could create in accessing especially dotNet objects? I
> > > just
> > > > > > checked and my update loop is running only about 5X/second right
> > now,
> > > > > though
> > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > really
> > > > > > need to be sped up.
> > > > > >
> > > > > > How would you do it?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > a
> > > > > > > reference to a control you are using(best bet is the main window)
> > to
> > > > > your
> > > > > > > middle layer.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > control
> > > > > > as
> > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > >
> > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > and
> > > > > > > high-level. All communications passes through that layer, and it
> > > also
> > > > > > allows
> > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > test
> > > > > > the
> > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Who you calling Gary? ;)
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Clarify KM"gasket" please.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Gary,
> > > > > > > >
> > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > assume
> > > > > > > that
> > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > something
> > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would ditch the timer as well, using a service thread to
> > > interact
> > > > > > with
> > > > > > > > the
> > > > > > > > > kflop will be much smoother.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Instead of running your updates via your timer's callback you
> > > can
> > > > > > either
> > > > > > > > use
> > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > using
> > > > > > > > .net4.0
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Parallel tasks are best because the will automagically load
> > your
> > > cpu
> > > > > > > usage
> > > > > > > > > based on how many cores are available, etc.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Background workers are pretty easy to use and have a
> > > comprehensive
> > > > > use
> > > > > > > > > model.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > easy
> > > > > to
> > > > > > > use
> > > > > > > > to
> > > > > > > > > and easy to read.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > your
> > > > > > control
> > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > pseudo-example
> > > > > > > > > where I am using a common method that takes an Action as a
> > > parameter
> > > > > > and
> > > > > > > > > decides whether to invoke or not::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > is
> > > > > > > > > coming from a thread other than the GUI
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > thread
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > else
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > invocation required
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > In the updating method of whichever threading model you chose,
> > > you
> > > > > can
> > > > > > > use
> > > > > > > > > the above method like so::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > //Put your control updating code here.
> > > > > > > > >
> > > > > > > > > //Example:
> > > > > > > > >
> > > > > > > > > lblXaxisDest.Text =
> > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > >
> > > > > > > > > }));
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > So, I've been exercising my app on the machine, and for the
> > most
> > > > > > parts,
> > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > For
> > > > > > > > example,
> > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > execute a
> > > > > > line
> > > > > > > > of
> > > > > > > > > G-code containing nothing more than a single comment. When
> > > running,
> > > > > > the
> > > > > > > > DROs
> > > > > > > > > update in significant increments, rather than the relatively
> > > smooth
> > > > > > > > updates
> > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > 100mSec,
> > > > > > so
> > > > > > > I
> > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > my
> > > > > > code,
> > > > > > > so
> > > > > > > > > none of this concerns me at all at this early stage of the
> > game.
> > > > > > > > >
> > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > threads,
> > > > > > > I've
> > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > question
> > > > > > > > under
> > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > KMotionCNC,
> > > > > > > they
> > > > > > > > > both execute correctly first time, every time, without fail.
> > > But,
> > > > > run
> > > > > > > them
> > > > > > > > > under my app, using the few lines of code posted last night,
> > and
> > > the
> > > > > > > > threads
> > > > > > > > > start, may, or may not, make the first move, then go out to
> > > lunch.
> > > > > > > KMotion
> > > > > > > > > confirms the threads remain running long after they should
> > have
> > > > > > > > terminated,
> > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > here's
> > > the
> > > > > > > > bizarre
> > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > open
> > > > > the
> > > > > > > app
> > > > > > > > -
> > > > > > > > > the thread immediately picks up and runs to completion
> > > correctly! If
> > > > > I
> > > > > > > > just
> > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > work
> > > > > > > > perfectly
> > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > message
> > > > > > to
> > > > > > > > the
> > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > MsgBox
> > > > > > > does
> > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > thread
> > > > > was
> > > > > > > > > launched from MY app!
> > > > > > > > >
> > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > my
> > > DSP
> > > > > > > > programs
> > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > when
> > > > > it
> > > > > > > did
> > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > that's
> > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > here...
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3484 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I have all the locks in, and it seems no more broken than it was before. I'm getting a lot of hangs now, always in dotNet or KMotion. In one case, I launched by spindle control program on thread 2, then enter a polling loop to wait for it to complete, but status for thread 2 always come back as "running". But when I look in KMotion, thread 2 is NOT running! At other times, it's stuck in one of the DLL calls. Something I did in the process of moving the GUI updates to the BackgroundWorker has made this problem MUCH worse.

Are you able to reproduce the problem, in the test program I posted earlier? Since this is failing so readily now, do you want me to post it for you?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello Ray,
>
> Yes, lock every call.
>
>
> MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
>
> looking forward to hearing back your results.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> >
> > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> >
> > Regards,
> > Ray L.
> >
> >
> > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > with the only goal of finding your problem.
> > >
> > >
> > >
> > >
> > >
> > > Before that , you could try to surround any calls to the KM_Controller
> > > instance with a lock clause. This will allow only one thread at a time to
> > > access the controller object.
> > >
> > >
> > >
> > > Example::
> > >
> > >
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > var status = _Controller.WriteLineReadLine("Version");
> > >
> > >
> > >
> > > var status2 = _Controller.WriteLineReadLine("Version");
> > >
> > > }
> > >
> > >
> > >
> > > Basically, any function you are using the KM_Controller instance in may need
> > > to be placed in a lock.
> > >
> > >
> > >
> > > Example2::
> > >
> > >
> > >
> > > Public void MyUpdatingOrCommandingFunction(args….)
> > >
> > > {
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > //Do stuff with your controller here
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > Try this and let me know if it helps. It is making sense to me that the
> > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > I never ran into it on MM as it never accesses the GUI thread.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 9:14 PM
> > > To: DynoMotion@yahoogroups.com
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > But perhaps a simple example:
> > >
> > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > current tool, spindle RPM, and a number of other things. Those are currently
> > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > >
> > > Some of the Button Click handlers also need to access things in
> > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > method in my dotNet "gasket" that handles all this.
> > >
> > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > be better to have only one thread talking the KM_Controller? If so, should I
> > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > vice-versa. Or perhaps there's another/better option?
> > >
> > > I looked through your HTML app code, but you don't seem to be dealing with
> > > that problem yet, since it appears to me only the DROs are actually
> > > functional, and their operation is straight-forward (though I note you are
> > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Hello Ray,
> > > >
> > > >
> > > >
> > > > I would probably need to see some code to be much help.
> > > >
> > > >
> > > >
> > > > Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > clear on the right way to handle communications with dotNet. My UI update
> > > > thread needs to access various dotNet data to create the updates. Right
> > > now,
> > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > contains the UI status, then tossing that over to the UI thread to update
> > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > thread? Or is there a better way?
> > > >
> > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > to
> > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > but
> > > > doesn't exit.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > but,
> > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > display update performance. It also, not surprisingly, introduced a couple
> > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > still
> > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > called. Not sure I understand why that's happening.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > The only thing I will add at this point is try it and you will see.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > rendering
> > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > can
> > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > update
> > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > controls. I already update the DROs more often than the other
> > > controls,
> > > > by
> > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > ticks.
> > > > > > How will another thread improve performance, if the bottleneck is
> > > > getting
> > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > since
> > > > > > I have to go through an invoke to modify each control?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > >
> > > > > > > First off, you never want to have too many threads running,
> > > > technically
> > > > > > you
> > > > > > > can only have one run per core and anything after that is going to
> > > be
> > > > time
> > > > > > > slicing.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > HTML
> > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > earlier.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > loop
> > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > Within
> > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > and
> > > > > > > when that happens I update the less important items.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Very basic setup that only uses one additional thread that updates
> > > the
> > > > > > DRO's
> > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > updated
> > > > > > > every ½ a second.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will re-upload my source so you can see how it works.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > >
> > > > > > > I can see how I could use parallel threads to make the display
> > > updates
> > > > > > more
> > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > concurrency
> > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > just
> > > > > > > checked and my update loop is running only about 5X/second right
> > > now,
> > > > > > though
> > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > really
> > > > > > > need to be sped up.
> > > > > > >
> > > > > > > How would you do it?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > a
> > > > > > > > reference to a control you are using(best bet is the main window)
> > > to
> > > > > > your
> > > > > > > > middle layer.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > control
> > > > > > > as
> > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > >
> > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > and
> > > > > > > > high-level. All communications passes through that layer, and it
> > > > also
> > > > > > > allows
> > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > test
> > > > > > > the
> > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Who you calling Gary? ;)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Gary,
> > > > > > > > >
> > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > assume
> > > > > > > > that
> > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > something
> > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > interact
> > > > > > > with
> > > > > > > > > the
> > > > > > > > > > kflop will be much smoother.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > can
> > > > > > > either
> > > > > > > > > use
> > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > using
> > > > > > > > > .net4.0
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Parallel tasks are best because the will automagically load
> > > your
> > > > cpu
> > > > > > > > usage
> > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Background workers are pretty easy to use and have a
> > > > comprehensive
> > > > > > use
> > > > > > > > > > model.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > easy
> > > > > > to
> > > > > > > > use
> > > > > > > > > to
> > > > > > > > > > and easy to read.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > your
> > > > > > > control
> > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > pseudo-example
> > > > > > > > > > where I am using a common method that takes an Action as a
> > > > parameter
> > > > > > > and
> > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > is
> > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > thread
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > else
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > invocation required
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > you
> > > > > > can
> > > > > > > > use
> > > > > > > > > > the above method like so::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > //Put your control updating code here.
> > > > > > > > > >
> > > > > > > > > > //Example:
> > > > > > > > > >
> > > > > > > > > > lblXaxisDest.Text =
> > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > >
> > > > > > > > > > }));
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > most
> > > > > > > parts,
> > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > For
> > > > > > > > > example,
> > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > execute a
> > > > > > > line
> > > > > > > > > of
> > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > running,
> > > > > > > the
> > > > > > > > > DROs
> > > > > > > > > > update in significant increments, rather than the relatively
> > > > smooth
> > > > > > > > > updates
> > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > 100mSec,
> > > > > > > so
> > > > > > > > I
> > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > my
> > > > > > > code,
> > > > > > > > so
> > > > > > > > > > none of this concerns me at all at this early stage of the
> > > game.
> > > > > > > > > >
> > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > threads,
> > > > > > > > I've
> > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > question
> > > > > > > > > under
> > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > KMotionCNC,
> > > > > > > > they
> > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > But,
> > > > > > run
> > > > > > > > them
> > > > > > > > > > under my app, using the few lines of code posted last night,
> > > and
> > > > the
> > > > > > > > > threads
> > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > lunch.
> > > > > > > > KMotion
> > > > > > > > > > confirms the threads remain running long after they should
> > > have
> > > > > > > > > terminated,
> > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > here's
> > > > the
> > > > > > > > > bizarre
> > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > open
> > > > > > the
> > > > > > > > app
> > > > > > > > > -
> > > > > > > > > > the thread immediately picks up and runs to completion
> > > > correctly! If
> > > > > > I
> > > > > > > > > just
> > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > work
> > > > > > > > > perfectly
> > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > message
> > > > > > > to
> > > > > > > > > the
> > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > MsgBox
> > > > > > > > does
> > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > thread
> > > > > > was
> > > > > > > > > > launched from MY app!
> > > > > > > > > >
> > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > my
> > > > DSP
> > > > > > > > > programs
> > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > when
> > > > > > it
> > > > > > > > did
> > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > that's
> > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > here...
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3485 From: Tom Kerekes Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Guys,
 
I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
 
Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
 
#1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
 
The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
 
The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
 
There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
 
#2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
 
#3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.

Anyway, just some thoughts..
Thanks
TK
 
 
From: bradodarb <bradodarb@...>
To: DynoMotion@yahoogroups.com
Sent: Thursday, January 26, 2012 8:46 PM
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 
Hello Ray,

Yes, lock every call.

MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.

looking forward to hearing back your results.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
>
> "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
>
> Regards,
> Ray L.
>
>
> --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> >
> > As far as your code goes, I would be looking with an non-judgmental eye and
> > with the only goal of finding your problem.
> >
> >
> >
> >
> >
> > Before that , you could try to surround any calls to the KM_Controller
> > instance with a lock clause. This will allow only one thread at a time to
> > access the controller object.
> >
> >
> >
> > Example::
> >
> >
> >
> > lock(_Controller)
> >
> > {
> >
> > var status = _Controller.WriteLineReadLine("Version");
> >
> >
> >
> > var status2 = _Controller.WriteLineReadLine("Version");
> >
> > }
> >
> >
> >
> > Basically, any function you are using the KM_Controller instance in may need
> > to be placed in a lock.
> >
> >
> >
> > Example2::
> >
> >
> >
> > Public void MyUpdatingOrCommandingFunction(args….)
> >
> > {
> >
> > lock(_Controller)
> >
> > {
> >
> > //Do stuff with your controller here
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > Try this and let me know if it helps. It is making sense to me that the
> > KM_Controller is not Thread safe as it is maintaining pointer references….
> > I never ran into it on MM as it never accesses the GUI thread.
> >
> >
> >
> > -Brad Murry
> >
> > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > Behalf Of himykabibble
> > Sent: Thursday, January 26, 2012 9:14 PM
> > To: DynoMotion@yahoogroups.com
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > I'd be happy to send you my code, if you promise not to laugh too hard....
> > But perhaps a simple example:
> >
> > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > current tool, spindle RPM, and a number of other things. Those are currently
> > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> >
> > Some of the Button Click handlers also need to access things in
> > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > method in my dotNet "gasket" that handles all this.
> >
> > So, My KM_Controller is currently getting called by both the UI thread, and
> > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > be better to have only one thread talking the KM_Controller? If so, should I
> > move all calls from the BackgroundWorker thread to the UI thread, or
> > vice-versa. Or perhaps there's another/better option?
> >
> > I looked through your HTML app code, but you don't seem to be dealing with
> > that problem yet, since it appears to me only the DROs are actually
> > functional, and their operation is straight-forward (though I note you are
> > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Hello Ray,
> > >
> > >
> > >
> > > I would probably need to see some code to be much help.
> > >
> > >
> > >
> > > Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 8:57 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > clear on the right way to handle communications with dotNet. My UI update
> > > thread needs to access various dotNet data to create the updates. Right
> > now,
> > > I'm doing those accesses in the DoWork method, creating an object that
> > > contains the UI status, then tossing that over to the UI thread to update
> > > the controls. But, the UI thread also needs to access dotNet when things
> > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > thread? Or is there a better way?
> > >
> > > Right now, something I've done has made the hangs much worse. I'm getting
> > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > to
> > > get the BackgroundWorker thread to exit. It stops updating the display,
> > but
> > > doesn't exit.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > plagiarizing what you do in your HTML app. It was relatively painless,
> > but,
> > > surprisingly, didn't really make any perceptible difference in terms of
> > > display update performance. It also, not surprisingly, introduced a couple
> > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > still
> > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > called. Not sure I understand why that's happening.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > The only thing I will add at this point is try it and you will see.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > I will add that MM uses a multi-threading model, has a lot more
> > > rendering
> > > > > going on that a winforms app, also does openGL toolpath display and I
> > > can
> > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Nowadays any non-trivial app requires multi-threading.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -Brad
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > update
> > > > > time is getting the information from dotNet, not actually updating the
> > > > > controls. I already update the DROs more often than the other
> > controls,
> > > by
> > > > > just doing the DROs on every timer tick, and the others on alternate
> > > ticks.
> > > > > How will another thread improve performance, if the bottleneck is
> > > getting
> > > > > the update data (which comes primarily from MainStatus), particularly
> > > since
> > > > > I have to go through an invoke to modify each control?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > >
> > > > > > First off, you never want to have too many threads running,
> > > technically
> > > > > you
> > > > > > can only have one run per core and anything after that is going to
> > be
> > > time
> > > > > > slicing.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > HTML
> > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > earlier.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > loop
> > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > Within
> > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > and
> > > > > > when that happens I update the less important items.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Very basic setup that only uses one additional thread that updates
> > the
> > > > > DRO's
> > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > updated
> > > > > > every ½ a second.
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will re-upload my source so you can see how it works.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > >
> > > > > > I can see how I could use parallel threads to make the display
> > updates
> > > > > more
> > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > controls). I assume the wonders of .NET will deal with all the
> > > concurrency
> > > > > > issues that could create in accessing especially dotNet objects? I
> > > just
> > > > > > checked and my update loop is running only about 5X/second right
> > now,
> > > > > though
> > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > really
> > > > > > need to be sped up.
> > > > > >
> > > > > > How would you do it?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > a
> > > > > > > reference to a control you are using(best bet is the main window)
> > to
> > > > > your
> > > > > > > middle layer.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > control
> > > > > > as
> > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > >
> > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > and
> > > > > > > high-level. All communications passes through that layer, and it
> > > also
> > > > > > allows
> > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > test
> > > > > > the
> > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Who you calling Gary? ;)
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Clarify KM"gasket" please.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Gary,
> > > > > > > >
> > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > assume
> > > > > > > that
> > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > something
> > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would ditch the timer as well, using a service thread to
> > > interact
> > > > > > with
> > > > > > > > the
> > > > > > > > > kflop will be much smoother.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Instead of running your updates via your timer's callback you
> > > can
> > > > > > either
> > > > > > > > use
> > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > using
> > > > > > > > .net4.0
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Parallel tasks are best because the will automagically load
> > your
> > > cpu
> > > > > > > usage
> > > > > > > > > based on how many cores are available, etc.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Background workers are pretty easy to use and have a
> > > comprehensive
> > > > > use
> > > > > > > > > model.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > easy
> > > > > to
> > > > > > > use
> > > > > > > > to
> > > > > > > > > and easy to read.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > your
> > > > > > control
> > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > pseudo-example
> > > > > > > > > where I am using a common method that takes an Action as a
> > > parameter
> > > > > > and
> > > > > > > > > decides whether to invoke or not::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > is
> > > > > > > > > coming from a thread other than the GUI
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > thread
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > else
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > invocation required
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > In the updating method of whichever threading model you chose,
> > > you
> > > > > can
> > > > > > > use
> > > > > > > > > the above method like so::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > //Put your control updating code here.
> > > > > > > > >
> > > > > > > > > //Example:
> > > > > > > > >
> > > > > > > > > lblXaxisDest.Text =
> > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > >
> > > > > > > > > }));
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > So, I've been exercising my app on the machine, and for the
> > most
> > > > > > parts,
> > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > For
> > > > > > > > example,
> > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > execute a
> > > > > > line
> > > > > > > > of
> > > > > > > > > G-code containing nothing more than a single comment. When
> > > running,
> > > > > > the
> > > > > > > > DROs
> > > > > > > > > update in significant increments, rather than the relatively
> > > smooth
> > > > > > > > updates
> > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > 100mSec,
> > > > > > so
> > > > > > > I
> > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > my
> > > > > > code,
> > > > > > > so
> > > > > > > > > none of this concerns me at all at this early stage of the
> > game.
> > > > > > > > >
> > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > threads,
> > > > > > > I've
> > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > question
> > > > > > > > under
> > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > KMotionCNC,
> > > > > > > they
> > > > > > > > > both execute correctly first time, every time, without fail.
> > > But,
> > > > > run
> > > > > > > them
> > > > > > > > > under my app, using the few lines of code posted last night,
> > and
> > > the
> > > > > > > > threads
> > > > > > > > > start, may, or may not, make the first move, then go out to
> > > lunch.
> > > > > > > KMotion
> > > > > > > > > confirms the threads remain running long after they should
> > have
> > > > > > > > terminated,
> > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > here's
> > > the
> > > > > > > > bizarre
> > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > open
> > > > > the
> > > > > > > app
> > > > > > > > -
> > > > > > > > > the thread immediately picks up and runs to completion
> > > correctly! If
> > > > > I
> > > > > > > > just
> > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > work
> > > > > > > > perfectly
> > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > message
> > > > > > to
> > > > > > > > the
> > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > MsgBox
> > > > > > > does
> > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > thread
> > > > > was
> > > > > > > > > launched from MY app!
> > > > > > > > >
> > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > my
> > > DSP
> > > > > > > > programs
> > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > when
> > > > > it
> > > > > > > did
> > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > that's
> > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > here...
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>



Group: DynoMotion Message: 3486 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom,

I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).

I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)

BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Guys,
>  
> I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
>  
> Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
>  
> #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
>  
> The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
>  
> The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
>  
> There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
>  
> #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
>  
> #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
>
> Anyway, just some thoughts..
> Thanks
> TK
>  
>  
>
> ________________________________
> From: bradodarb <bradodarb@...>
> To: DynoMotion@yahoogroups.com
> Sent: Thursday, January 26, 2012 8:46 PM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
>
> Hello Ray,
>
> Yes, lock every call.
>
> MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
>
> looking forward to hearing back your results.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> >
> > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> >
> > Regards,
> > Ray L.
> >
> >
> > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > with the only goal of finding your problem.
> > >
> > >
> > >
> > >
> > >
> > > Before that , you could try to surround any calls to the KM_Controller
> > > instance with a lock clause. This will allow only one thread at a time to
> > > access the controller object.
> > >
> > >
> > >
> > > Example::
> > >
> > >
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > var status = _Controller.WriteLineReadLine("Version");
> > >
> > >
> > >
> > > var status2 = _Controller.WriteLineReadLine("Version");
> > >
> > > }
> > >
> > >
> > >
> > > Basically, any function you are using the KM_Controller instance in may need
> > > to be placed in a lock.
> > >
> > >
> > >
> > > Example2::
> > >
> > >
> > >
> > > Public void MyUpdatingOrCommandingFunction(args….)
> > >
> > > {
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > //Do stuff with your controller here
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > Try this and let me know if it helps. It is making sense to me that the
> > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > I never ran into it on MM as it never accesses the GUI thread.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 9:14 PM
> > > To: DynoMotion@yahoogroups.com
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > But perhaps a simple example:
> > >
> > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > current tool, spindle RPM, and a number of other things. Those are currently
> > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > >
> > > Some of the Button Click handlers also need to access things in
> > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > method in my dotNet "gasket" that handles all this.
> > >
> > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > be better to have only one thread talking the KM_Controller? If so, should I
> > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > vice-versa. Or perhaps there's another/better option?
> > >
> > > I looked through your HTML app code, but you don't seem to be dealing with
> > > that problem yet, since it appears to me only the DROs are actually
> > > functional, and their operation is straight-forward (though I note you are
> > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Hello Ray,
> > > >
> > > >
> > > >
> > > > I would probably need to see some code to be much help.
> > > >
> > > >
> > > >
> > > > Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > clear on the right way to handle communications with dotNet. My UI update
> > > > thread needs to access various dotNet data to create the updates. Right
> > > now,
> > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > contains the UI status, then tossing that over to the UI thread to update
> > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > thread? Or is there a better way?
> > > >
> > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > to
> > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > but
> > > > doesn't exit.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > but,
> > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > display update performance. It also, not surprisingly, introduced a couple
> > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > still
> > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > called. Not sure I understand why that's happening.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > The only thing I will add at this point is try it and you will see.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > rendering
> > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > can
> > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > update
> > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > controls. I already update the DROs more often than the other
> > > controls,
> > > > by
> > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > ticks.
> > > > > > How will another thread improve performance, if the bottleneck is
> > > > getting
> > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > since
> > > > > > I have to go through an invoke to modify each control?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > >
> > > > > > > First off, you never want to have too many threads running,
> > > > technically
> > > > > > you
> > > > > > > can only have one run per core and anything after that is going to
> > > be
> > > > time
> > > > > > > slicing.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > HTML
> > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > earlier.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > loop
> > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > Within
> > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > and
> > > > > > > when that happens I update the less important items.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Very basic setup that only uses one additional thread that updates
> > > the
> > > > > > DRO's
> > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > updated
> > > > > > > every ½ a second.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will re-upload my source so you can see how it works.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > >
> > > > > > > I can see how I could use parallel threads to make the display
> > > updates
> > > > > > more
> > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > concurrency
> > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > just
> > > > > > > checked and my update loop is running only about 5X/second right
> > > now,
> > > > > > though
> > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > really
> > > > > > > need to be sped up.
> > > > > > >
> > > > > > > How would you do it?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > a
> > > > > > > > reference to a control you are using(best bet is the main window)
> > > to
> > > > > > your
> > > > > > > > middle layer.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > control
> > > > > > > as
> > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > >
> > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > and
> > > > > > > > high-level. All communications passes through that layer, and it
> > > > also
> > > > > > > allows
> > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > test
> > > > > > > the
> > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Who you calling Gary? ;)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Gary,
> > > > > > > > >
> > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > assume
> > > > > > > > that
> > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > something
> > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > interact
> > > > > > > with
> > > > > > > > > the
> > > > > > > > > > kflop will be much smoother.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > can
> > > > > > > either
> > > > > > > > > use
> > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > using
> > > > > > > > > .net4.0
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Parallel tasks are best because the will automagically load
> > > your
> > > > cpu
> > > > > > > > usage
> > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Background workers are pretty easy to use and have a
> > > > comprehensive
> > > > > > use
> > > > > > > > > > model.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > easy
> > > > > > to
> > > > > > > > use
> > > > > > > > > to
> > > > > > > > > > and easy to read.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > your
> > > > > > > control
> > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > pseudo-example
> > > > > > > > > > where I am using a common method that takes an Action as a
> > > > parameter
> > > > > > > and
> > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > is
> > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > thread
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > else
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > invocation required
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > you
> > > > > > can
> > > > > > > > use
> > > > > > > > > > the above method like so::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > //Put your control updating code here.
> > > > > > > > > >
> > > > > > > > > > //Example:
> > > > > > > > > >
> > > > > > > > > > lblXaxisDest.Text =
> > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > >
> > > > > > > > > > }));
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > most
> > > > > > > parts,
> > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > For
> > > > > > > > > example,
> > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > execute a
> > > > > > > line
> > > > > > > > > of
> > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > running,
> > > > > > > the
> > > > > > > > > DROs
> > > > > > > > > > update in significant increments, rather than the relatively
> > > > smooth
> > > > > > > > > updates
> > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > 100mSec,
> > > > > > > so
> > > > > > > > I
> > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > my
> > > > > > > code,
> > > > > > > > so
> > > > > > > > > > none of this concerns me at all at this early stage of the
> > > game.
> > > > > > > > > >
> > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > threads,
> > > > > > > > I've
> > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > question
> > > > > > > > > under
> > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > KMotionCNC,
> > > > > > > > they
> > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > But,
> > > > > > run
> > > > > > > > them
> > > > > > > > > > under my app, using the few lines of code posted last night,
> > > and
> > > > the
> > > > > > > > > threads
> > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > lunch.
> > > > > > > > KMotion
> > > > > > > > > > confirms the threads remain running long after they should
> > > have
> > > > > > > > > terminated,
> > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > here's
> > > > the
> > > > > > > > > bizarre
> > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > open
> > > > > > the
> > > > > > > > app
> > > > > > > > > -
> > > > > > > > > > the thread immediately picks up and runs to completion
> > > > correctly! If
> > > > > > I
> > > > > > > > > just
> > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > work
> > > > > > > > > perfectly
> > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > message
> > > > > > > to
> > > > > > > > > the
> > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > MsgBox
> > > > > > > > does
> > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > thread
> > > > > > was
> > > > > > > > > > launched from MY app!
> > > > > > > > > >
> > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > my
> > > > DSP
> > > > > > > > > programs
> > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > when
> > > > > > it
> > > > > > > > did
> > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > that's
> > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > here...
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3487 From: Brad Murry Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Ray,

 

I will try your test app and post my findings.

 

-Brad

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Thursday, January 26, 2012 10:56 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

I have all the locks in, and it seems no more broken than it was before. I'm getting a lot of hangs now, always in dotNet or KMotion. In one case, I launched by spindle control program on thread 2, then enter a polling loop to wait for it to complete, but status for thread 2 always come back as "running". But when I look in KMotion, thread 2 is NOT running! At other times, it's stuck in one of the DLL calls. Something I did in the process of moving the GUI updates to the BackgroundWorker has made this problem MUCH worse.

Are you able to reproduce the problem, in the test program I posted earlier? Since this is failing so readily now, do you want me to post it for you?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello Ray,
>
> Yes, lock every call.
>
>
> MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
>
> looking forward to hearing back your results.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> >
> > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> >
> > Regards,
> > Ray L.
> >
> >
> > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > with the only goal of finding your problem.
> > >
> > >
> > >
> > >
> > >
> > > Before that , you could try to surround any calls to the KM_Controller
> > > instance with a lock clause. This will allow only one thread at a time to
> > > access the controller object.
> > >
> > >
> > >
> > > Example::
> > >
> > >
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > var status = _Controller.WriteLineReadLine("Version");
> > >
> > >
> > >
> > > var status2 = _Controller.WriteLineReadLine("Version");
> > >
> > > }
> > >
> > >
> > >
> > > Basically, any function you are using the KM_Controller instance in may need
> > > to be placed in a lock.
> > >
> > >
> > >
> > > Example2::
> > >
> > >
> > >
> > > Public void MyUpdatingOrCommandingFunction(args….)
> > >
> > > {
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > //Do stuff with your controller here
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > Try this and let me know if it helps. It is making sense to me that the
> > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > I never ran into it on MM as it never accesses the GUI thread.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 9:14 PM
> > > To: DynoMotion@yahoogroups.com
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > But perhaps a simple example:
> > >
> > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > current tool, spindle RPM, and a number of other things. Those are currently
> > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > >
> > > Some of the Button Click handlers also need to access things in
> > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > method in my dotNet "gasket" that handles all this.
> > >
> > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > be better to have only one thread talking the KM_Controller? If so, should I
> > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > vice-versa. Or perhaps there's another/better option?
> > >
> > > I looked through your HTML app code, but you don't seem to be dealing with
> > > that problem yet, since it appears to me only the DROs are actually
> > > functional, and their operation is straight-forward (though I note you are
> > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Hello Ray,
> > > >
> > > >
> > > >
> > > > I would probably need to see some code to be much help.
> > > >
> > > >
> > > >
> > > > Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > clear on the right way to handle communications with dotNet. My UI update
> > > > thread needs to access various dotNet data to create the updates. Right
> > > now,
> > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > contains the UI status, then tossing that over to the UI thread to update
> > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > thread? Or is there a better way?
> > > >
> > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > to
> > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > but
> > > > doesn't exit.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > but,
> > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > display update performance. It also, not surprisingly, introduced a couple
> > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > still
> > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > called. Not sure I understand why that's happening.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > The only thing I will add at this point is try it and you will see.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > rendering
> > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > can
> > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > update
> > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > controls. I already update the DROs more often than the other
> > > controls,
> > > > by
> > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > ticks.
> > > > > > How will another thread improve performance, if the bottleneck is
> > > > getting
> > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > since
> > > > > > I have to go through an invoke to modify each control?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > >
> > > > > > > First off, you never want to have too many threads running,
> > > > technically
> > > > > > you
> > > > > > > can only have one run per core and anything after that is going to
> > > be
> > > > time
> > > > > > > slicing.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > HTML
> > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > earlier.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > loop
> > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > Within
> > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > and
> > > > > > > when that happens I update the less important items.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Very basic setup that only uses one additional thread that updates
> > > the
> > > > > > DRO's
> > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > updated
> > > > > > > every ½ a second.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will re-upload my source so you can see how it works.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > >
> > > > > > > I can see how I could use parallel threads to make the display
> > > updates
> > > > > > more
> > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > concurrency
> > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > just
> > > > > > > checked and my update loop is running only about 5X/second right
> > > now,
> > > > > > though
> > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > really
> > > > > > > need to be sped up.
> > > > > > >
> > > > > > > How would you do it?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > a
> > > > > > > > reference to a control you are using(best bet is the main window)
> > > to
> > > > > > your
> > > > > > > > middle layer.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > control
> > > > > > > as
> > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > >
> > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > and
> > > > > > > > high-level. All communications passes through that layer, and it
> > > > also
> > > > > > > allows
> > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > test
> > > > > > > the
> > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Who you calling Gary? ;)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Gary,
> > > > > > > > >
> > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > assume
> > > > > > > > that
> > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > something
> > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > interact
> > > > > > > with
> > > > > > > > > the
> > > > > > > > > > kflop will be much smoother.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > can
> > > > > > > either
> > > > > > > > > use
> > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > using
> > > > > > > > > .net4.0
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Parallel tasks are best because the will automagically load
> > > your
> > > > cpu
> > > > > > > > usage
> > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Background workers are pretty easy to use and have a
> > > > comprehensive
> > > > > > use
> > > > > > > > > > model.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > easy
> > > > > > to
> > > > > > > > use
> > > > > > > > > to
> > > > > > > > > > and easy to read.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > your
> > > > > > > control
> > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > pseudo-example
> > > > > > > > > > where I am using a common method that takes an Action as a
> > > > parameter
> > > > > > > and
> > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > is
> > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > thread
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > else
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > invocation required
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > you
> > > > > > can
> > > > > > > > use
> > > > > > > > > > the above method like so::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > //Put your control updating code here.
> > > > > > > > > >
> > > > > > > > > > //Example:
> > > > > > > > > >
> > > > > > > > > > lblXaxisDest.Text =
> > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > >
> > > > > > > > > > }));
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > most
> > > > > > > parts,
> > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > For
> > > > > > > > > example,
> > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > execute a
> > > > > > > line
> > > > > > > > > of
> > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > running,
> > > > > > > the
> > > > > > > > > DROs
> > > > > > > > > > update in significant increments, rather than the relatively
> > > > smooth
> > > > > > > > > updates
> > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > 100mSec,
> > > > > > > so
> > > > > > > > I
> > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > my
> > > > > > > code,
> > > > > > > > so
> > > > > > > > > > none of this concerns me at all at this early stage of the
> > > game.
> > > > > > > > > >
> > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > threads,
> > > > > > > > I've
> > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > question
> > > > > > > > > under
> > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > KMotionCNC,
> > > > > > > > they
> > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > But,
> > > > > > run
> > > > > > > > them
> > > > > > > > > > under my app, using the few lines of code posted last night,
> > > and
> > > > the
> > > > > > > > > threads
> > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > lunch.
> > > > > > > > KMotion
> > > > > > > > > > confirms the threads remain running long after they should
> > > have
> > > > > > > > > terminated,
> > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > here's
> > > > the
> > > > > > > > > bizarre
> > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > open
> > > > > > the
> > > > > > > > app
> > > > > > > > > -
> > > > > > > > > > the thread immediately picks up and runs to completion
> > > > correctly! If
> > > > > > I
> > > > > > > > > just
> > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > work
> > > > > > > > > perfectly
> > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > message
> > > > > > > to
> > > > > > > > > the
> > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > MsgBox
> > > > > > > > does
> > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > thread
> > > > > > was
> > > > > > > > > > launched from MY app!
> > > > > > > > > >
> > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > my
> > > > DSP
> > > > > > > > > programs
> > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > when
> > > > > > it
> > > > > > > > did
> > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > that's
> > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > here...
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Group: DynoMotion Message: 3488 From: bradodarb Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom/Ray,

Tom,

#1Good, but I suggested the lock to make sure we weren't trying to grab a token from multiple threads. I think I understand that the token will be atomic and only be given to the calling thread but my thoughts were a lock will cause the next calling thread to wait until the other thread is done.

#2 A separate GUI update thread is advantageous here because updating the data is taking <100ms at some times. If a timer is being used with say a 100ms interval and the task is taking 200ms then the GUI will be locked as the next timer `tick' event will have been fired before the last was completed.

By having the updating on a separate thread, the update process can take however long as is needed and update every cycle.

#3 The Task Parallel library in .net 4.0 will distribute amongst cores when possible.


Not saying the above is set in stone gospel(except 3), but is where I was coming from.

-Brad Murry


--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Tom,
>
> I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
>
> I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
>
> BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Guys,
> >  
> > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> >  
> > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> >  
> > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> >  
> > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> >  
> > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> >  
> > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> >  
> > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> >  
> > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> >
> > Anyway, just some thoughts..
> > Thanks
> > TK
> >  
> >  
> >
> > ________________________________
> > From: bradodarb <bradodarb@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Thursday, January 26, 2012 8:46 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> >
> > Hello Ray,
> >
> > Yes, lock every call.
> >
> > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> >
> > looking forward to hearing back your results.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > >
> > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > >
> > > Regards,
> > > Ray L.
> > >
> > >
> > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > >
> > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > with the only goal of finding your problem.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Before that , you could try to surround any calls to the KM_Controller
> > > > instance with a lock clause. This will allow only one thread at a time to
> > > > access the controller object.
> > > >
> > > >
> > > >
> > > > Example::
> > > >
> > > >
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > var status = _Controller.WriteLineReadLine("Version");
> > > >
> > > >
> > > >
> > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > Basically, any function you are using the KM_Controller instance in may need
> > > > to be placed in a lock.
> > > >
> > > >
> > > >
> > > > Example2::
> > > >
> > > >
> > > >
> > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > >
> > > > {
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > //Do stuff with your controller here
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Try this and let me know if it helps. It is making sense to me that the
> > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > I never ran into it on MM as it never accesses the GUI thread.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > To: DynoMotion@yahoogroups.com
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > But perhaps a simple example:
> > > >
> > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > >
> > > > Some of the Button Click handlers also need to access things in
> > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > method in my dotNet "gasket" that handles all this.
> > > >
> > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > vice-versa. Or perhaps there's another/better option?
> > > >
> > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > that problem yet, since it appears to me only the DROs are actually
> > > > functional, and their operation is straight-forward (though I note you are
> > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > >
> > > > >
> > > > > I would probably need to see some code to be much help.
> > > > >
> > > > >
> > > > >
> > > > > Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > thread needs to access various dotNet data to create the updates. Right
> > > > now,
> > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > thread? Or is there a better way?
> > > > >
> > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > to
> > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > but
> > > > > doesn't exit.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > but,
> > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > still
> > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > called. Not sure I understand why that's happening.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > rendering
> > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > can
> > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > update
> > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > controls. I already update the DROs more often than the other
> > > > controls,
> > > > > by
> > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > ticks.
> > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > getting
> > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > since
> > > > > > > I have to go through an invoke to modify each control?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > > First off, you never want to have too many threads running,
> > > > > technically
> > > > > > > you
> > > > > > > > can only have one run per core and anything after that is going to
> > > > be
> > > > > time
> > > > > > > > slicing.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > HTML
> > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > earlier.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > loop
> > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > Within
> > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > and
> > > > > > > > when that happens I update the less important items.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > the
> > > > > > > DRO's
> > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > updated
> > > > > > > > every ½ a second.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > >
> > > > > > > > I can see how I could use parallel threads to make the display
> > > > updates
> > > > > > > more
> > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > concurrency
> > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > just
> > > > > > > > checked and my update loop is running only about 5X/second right
> > > > now,
> > > > > > > though
> > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > really
> > > > > > > > need to be sped up.
> > > > > > > >
> > > > > > > > How would you do it?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > a
> > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > to
> > > > > > > your
> > > > > > > > > middle layer.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > control
> > > > > > > > as
> > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > >
> > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > and
> > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > also
> > > > > > > > allows
> > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > test
> > > > > > > > the
> > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Gary,
> > > > > > > > > >
> > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > assume
> > > > > > > > > that
> > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > something
> > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > interact
> > > > > > > > with
> > > > > > > > > > the
> > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > can
> > > > > > > > either
> > > > > > > > > > use
> > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > using
> > > > > > > > > > .net4.0
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > your
> > > > > cpu
> > > > > > > > > usage
> > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > comprehensive
> > > > > > > use
> > > > > > > > > > > model.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > easy
> > > > > > > to
> > > > > > > > > use
> > > > > > > > > > to
> > > > > > > > > > > and easy to read.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > your
> > > > > > > > control
> > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > pseudo-example
> > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > parameter
> > > > > > > > and
> > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > is
> > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > thread
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > else
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > invocation required
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > you
> > > > > > > can
> > > > > > > > > use
> > > > > > > > > > > the above method like so::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > >
> > > > > > > > > > > //Example:
> > > > > > > > > > >
> > > > > > > > > > > lblXaxisDest.Text =
> > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > >
> > > > > > > > > > > }));
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > most
> > > > > > > > parts,
> > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > For
> > > > > > > > > > example,
> > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > execute a
> > > > > > > > line
> > > > > > > > > > of
> > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > running,
> > > > > > > > the
> > > > > > > > > > DROs
> > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > smooth
> > > > > > > > > > updates
> > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > 100mSec,
> > > > > > > > so
> > > > > > > > > I
> > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > my
> > > > > > > > code,
> > > > > > > > > so
> > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > game.
> > > > > > > > > > >
> > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > threads,
> > > > > > > > > I've
> > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > question
> > > > > > > > > > under
> > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > KMotionCNC,
> > > > > > > > > they
> > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > But,
> > > > > > > run
> > > > > > > > > them
> > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > and
> > > > > the
> > > > > > > > > > threads
> > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > lunch.
> > > > > > > > > KMotion
> > > > > > > > > > > confirms the threads remain running long after they should
> > > > have
> > > > > > > > > > terminated,
> > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > here's
> > > > > the
> > > > > > > > > > bizarre
> > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > open
> > > > > > > the
> > > > > > > > > app
> > > > > > > > > > -
> > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > correctly! If
> > > > > > > I
> > > > > > > > > > just
> > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > work
> > > > > > > > > > perfectly
> > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > message
> > > > > > > > to
> > > > > > > > > > the
> > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > MsgBox
> > > > > > > > > does
> > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > thread
> > > > > > > was
> > > > > > > > > > > launched from MY app!
> > > > > > > > > > >
> > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > my
> > > > > DSP
> > > > > > > > > > programs
> > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > when
> > > > > > > it
> > > > > > > > > did
> > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > that's
> > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > here...
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3489 From: bradodarb Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Ray,


Once you pull all those locks out ;).....

Can you try something else for the sake of argument?

Remove the use of the MainStatus and just get the axis values from the
interpreter and get your IO status from your KM_IO objects.

I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.

Are you game?

-Brad Murry

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Tom,
>
> I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
>
> I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
>
> BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Guys,
> >  
> > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> >  
> > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> >  
> > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> >  
> > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> >  
> > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> >  
> > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> >  
> > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> >  
> > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> >
> > Anyway, just some thoughts..
> > Thanks
> > TK
> >  
> >  
> >
> > ________________________________
> > From: bradodarb <bradodarb@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Thursday, January 26, 2012 8:46 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> >
> > Hello Ray,
> >
> > Yes, lock every call.
> >
> > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> >
> > looking forward to hearing back your results.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > >
> > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > >
> > > Regards,
> > > Ray L.
> > >
> > >
> > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > >
> > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > with the only goal of finding your problem.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Before that , you could try to surround any calls to the KM_Controller
> > > > instance with a lock clause. This will allow only one thread at a time to
> > > > access the controller object.
> > > >
> > > >
> > > >
> > > > Example::
> > > >
> > > >
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > var status = _Controller.WriteLineReadLine("Version");
> > > >
> > > >
> > > >
> > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > Basically, any function you are using the KM_Controller instance in may need
> > > > to be placed in a lock.
> > > >
> > > >
> > > >
> > > > Example2::
> > > >
> > > >
> > > >
> > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > >
> > > > {
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > //Do stuff with your controller here
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Try this and let me know if it helps. It is making sense to me that the
> > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > I never ran into it on MM as it never accesses the GUI thread.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > To: DynoMotion@yahoogroups.com
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > But perhaps a simple example:
> > > >
> > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > >
> > > > Some of the Button Click handlers also need to access things in
> > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > method in my dotNet "gasket" that handles all this.
> > > >
> > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > vice-versa. Or perhaps there's another/better option?
> > > >
> > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > that problem yet, since it appears to me only the DROs are actually
> > > > functional, and their operation is straight-forward (though I note you are
> > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > >
> > > > >
> > > > > I would probably need to see some code to be much help.
> > > > >
> > > > >
> > > > >
> > > > > Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > thread needs to access various dotNet data to create the updates. Right
> > > > now,
> > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > thread? Or is there a better way?
> > > > >
> > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > to
> > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > but
> > > > > doesn't exit.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > but,
> > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > still
> > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > called. Not sure I understand why that's happening.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > rendering
> > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > can
> > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > update
> > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > controls. I already update the DROs more often than the other
> > > > controls,
> > > > > by
> > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > ticks.
> > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > getting
> > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > since
> > > > > > > I have to go through an invoke to modify each control?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > > First off, you never want to have too many threads running,
> > > > > technically
> > > > > > > you
> > > > > > > > can only have one run per core and anything after that is going to
> > > > be
> > > > > time
> > > > > > > > slicing.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > HTML
> > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > earlier.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > loop
> > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > Within
> > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > and
> > > > > > > > when that happens I update the less important items.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > the
> > > > > > > DRO's
> > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > updated
> > > > > > > > every ½ a second.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > >
> > > > > > > > I can see how I could use parallel threads to make the display
> > > > updates
> > > > > > > more
> > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > concurrency
> > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > just
> > > > > > > > checked and my update loop is running only about 5X/second right
> > > > now,
> > > > > > > though
> > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > really
> > > > > > > > need to be sped up.
> > > > > > > >
> > > > > > > > How would you do it?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > a
> > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > to
> > > > > > > your
> > > > > > > > > middle layer.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > control
> > > > > > > > as
> > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > >
> > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > and
> > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > also
> > > > > > > > allows
> > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > test
> > > > > > > > the
> > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Gary,
> > > > > > > > > >
> > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > assume
> > > > > > > > > that
> > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > something
> > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > interact
> > > > > > > > with
> > > > > > > > > > the
> > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > can
> > > > > > > > either
> > > > > > > > > > use
> > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > using
> > > > > > > > > > .net4.0
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > your
> > > > > cpu
> > > > > > > > > usage
> > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > comprehensive
> > > > > > > use
> > > > > > > > > > > model.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > easy
> > > > > > > to
> > > > > > > > > use
> > > > > > > > > > to
> > > > > > > > > > > and easy to read.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > your
> > > > > > > > control
> > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > pseudo-example
> > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > parameter
> > > > > > > > and
> > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > is
> > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > thread
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > else
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > invocation required
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > you
> > > > > > > can
> > > > > > > > > use
> > > > > > > > > > > the above method like so::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > >
> > > > > > > > > > > //Example:
> > > > > > > > > > >
> > > > > > > > > > > lblXaxisDest.Text =
> > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > >
> > > > > > > > > > > }));
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > most
> > > > > > > > parts,
> > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > For
> > > > > > > > > > example,
> > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > execute a
> > > > > > > > line
> > > > > > > > > > of
> > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > running,
> > > > > > > > the
> > > > > > > > > > DROs
> > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > smooth
> > > > > > > > > > updates
> > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > 100mSec,
> > > > > > > > so
> > > > > > > > > I
> > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > my
> > > > > > > > code,
> > > > > > > > > so
> > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > game.
> > > > > > > > > > >
> > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > threads,
> > > > > > > > > I've
> > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > question
> > > > > > > > > > under
> > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > KMotionCNC,
> > > > > > > > > they
> > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > But,
> > > > > > > run
> > > > > > > > > them
> > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > and
> > > > > the
> > > > > > > > > > threads
> > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > lunch.
> > > > > > > > > KMotion
> > > > > > > > > > > confirms the threads remain running long after they should
> > > > have
> > > > > > > > > > terminated,
> > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > here's
> > > > > the
> > > > > > > > > > bizarre
> > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > open
> > > > > > > the
> > > > > > > > > app
> > > > > > > > > > -
> > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > correctly! If
> > > > > > > I
> > > > > > > > > > just
> > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > work
> > > > > > > > > > perfectly
> > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > message
> > > > > > > > to
> > > > > > > > > > the
> > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > MsgBox
> > > > > > > > > does
> > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > thread
> > > > > > > was
> > > > > > > > > > > launched from MY app!
> > > > > > > > > > >
> > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > my
> > > > > DSP
> > > > > > > > > > programs
> > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > when
> > > > > > > it
> > > > > > > > > did
> > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > that's
> > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > here...
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3490 From: bradodarb Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Ray,

For clarity, please post your spindle.c files the bug tester is looking for so I can debug it.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Ray,
>
>
> Once you pull all those locks out ;).....
>
> Can you try something else for the sake of argument?
>
> Remove the use of the MainStatus and just get the axis values from the
> interpreter and get your IO status from your KM_IO objects.
>
> I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
>
> Are you game?
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Tom,
> >
> > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> >
> > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> >
> > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Guys,
> > >  
> > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > >  
> > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > >  
> > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > >  
> > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > >  
> > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > >  
> > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > >  
> > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > >  
> > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > >
> > > Anyway, just some thoughts..
> > > Thanks
> > > TK
> > >  
> > >  
> > >
> > > ________________________________
> > > From: bradodarb <bradodarb@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Thursday, January 26, 2012 8:46 PM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > >
> > > Hello Ray,
> > >
> > > Yes, lock every call.
> > >
> > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > >
> > > looking forward to hearing back your results.
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > >
> > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Ray,
> > > > >
> > > > >
> > > > >
> > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > with the only goal of finding your problem.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > access the controller object.
> > > > >
> > > > >
> > > > >
> > > > > Example::
> > > > >
> > > > >
> > > > >
> > > > > lock(_Controller)
> > > > >
> > > > > {
> > > > >
> > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > >
> > > > >
> > > > >
> > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > to be placed in a lock.
> > > > >
> > > > >
> > > > >
> > > > > Example2::
> > > > >
> > > > >
> > > > >
> > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > >
> > > > > {
> > > > >
> > > > > lock(_Controller)
> > > > >
> > > > > {
> > > > >
> > > > > //Do stuff with your controller here
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > Behalf Of himykabibble
> > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > But perhaps a simple example:
> > > > >
> > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > >
> > > > > Some of the Button Click handlers also need to access things in
> > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > method in my dotNet "gasket" that handles all this.
> > > > >
> > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > vice-versa. Or perhaps there's another/better option?
> > > > >
> > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > functional, and their operation is straight-forward (though I note you are
> > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Hello Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > I would probably need to see some code to be much help.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > now,
> > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > thread? Or is there a better way?
> > > > > >
> > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > to
> > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > but
> > > > > > doesn't exit.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > but,
> > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > still
> > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > called. Not sure I understand why that's happening.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > rendering
> > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > can
> > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > update
> > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > controls. I already update the DROs more often than the other
> > > > > controls,
> > > > > > by
> > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > ticks.
> > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > getting
> > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > since
> > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > First off, you never want to have too many threads running,
> > > > > > technically
> > > > > > > > you
> > > > > > > > > can only have one run per core and anything after that is going to
> > > > > be
> > > > > > time
> > > > > > > > > slicing.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > HTML
> > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > earlier.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > loop
> > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > Within
> > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > and
> > > > > > > > > when that happens I update the less important items.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > the
> > > > > > > > DRO's
> > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > updated
> > > > > > > > > every ½ a second.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > >
> > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > updates
> > > > > > > > more
> > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > concurrency
> > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > just
> > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > now,
> > > > > > > > though
> > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > really
> > > > > > > > > need to be sped up.
> > > > > > > > >
> > > > > > > > > How would you do it?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > a
> > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > to
> > > > > > > > your
> > > > > > > > > > middle layer.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > control
> > > > > > > > > as
> > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > >
> > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > and
> > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > also
> > > > > > > > > allows
> > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > test
> > > > > > > > > the
> > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Gary,
> > > > > > > > > > >
> > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > assume
> > > > > > > > > > that
> > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > something
> > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Ray,
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > interact
> > > > > > > > > with
> > > > > > > > > > > the
> > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > can
> > > > > > > > > either
> > > > > > > > > > > use
> > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > using
> > > > > > > > > > > .net4.0
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > your
> > > > > > cpu
> > > > > > > > > > usage
> > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > comprehensive
> > > > > > > > use
> > > > > > > > > > > > model.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > easy
> > > > > > > > to
> > > > > > > > > > use
> > > > > > > > > > > to
> > > > > > > > > > > > and easy to read.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > your
> > > > > > > > > control
> > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > pseudo-example
> > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > parameter
> > > > > > > > > and
> > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > is
> > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > thread
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > else
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > invocation required
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > you
> > > > > > > > can
> > > > > > > > > > use
> > > > > > > > > > > > the above method like so::
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > >
> > > > > > > > > > > > //Example:
> > > > > > > > > > > >
> > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > >
> > > > > > > > > > > > }));
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > most
> > > > > > > > > parts,
> > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > For
> > > > > > > > > > > example,
> > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > execute a
> > > > > > > > > line
> > > > > > > > > > > of
> > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > running,
> > > > > > > > > the
> > > > > > > > > > > DROs
> > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > smooth
> > > > > > > > > > > updates
> > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > 100mSec,
> > > > > > > > > so
> > > > > > > > > > I
> > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > my
> > > > > > > > > code,
> > > > > > > > > > so
> > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > game.
> > > > > > > > > > > >
> > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > threads,
> > > > > > > > > > I've
> > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > question
> > > > > > > > > > > under
> > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > KMotionCNC,
> > > > > > > > > > they
> > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > But,
> > > > > > > > run
> > > > > > > > > > them
> > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > and
> > > > > > the
> > > > > > > > > > > threads
> > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > lunch.
> > > > > > > > > > KMotion
> > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > have
> > > > > > > > > > > terminated,
> > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > here's
> > > > > > the
> > > > > > > > > > > bizarre
> > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > open
> > > > > > > > the
> > > > > > > > > > app
> > > > > > > > > > > -
> > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > correctly! If
> > > > > > > > I
> > > > > > > > > > > just
> > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > work
> > > > > > > > > > > perfectly
> > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > message
> > > > > > > > > to
> > > > > > > > > > > the
> > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > MsgBox
> > > > > > > > > > does
> > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > thread
> > > > > > > > was
> > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > >
> > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > my
> > > > > > DSP
> > > > > > > > > > > programs
> > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > when
> > > > > > > > it
> > > > > > > > > > did
> > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > that's
> > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > here...
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3491 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Ray,
>
>
> Once you pull all those locks out ;).....
>
> Can you try something else for the sake of argument?
>
> Remove the use of the MainStatus and just get the axis values from the
> interpreter and get your IO status from your KM_IO objects.
>
> I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
>
> Are you game?
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Tom,
> >
> > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> >
> > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> >
> > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Guys,
> > >  
> > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > >  
> > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > >  
> > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > >  
> > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > >  
> > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > >  
> > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > >  
> > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > >  
> > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > >
> > > Anyway, just some thoughts..
> > > Thanks
> > > TK
> > >  
> > >  
> > >
> > > ________________________________
> > > From: bradodarb <bradodarb@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Thursday, January 26, 2012 8:46 PM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > >
> > > Hello Ray,
> > >
> > > Yes, lock every call.
> > >
> > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > >
> > > looking forward to hearing back your results.
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > >
> > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Ray,
> > > > >
> > > > >
> > > > >
> > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > with the only goal of finding your problem.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > access the controller object.
> > > > >
> > > > >
> > > > >
> > > > > Example::
> > > > >
> > > > >
> > > > >
> > > > > lock(_Controller)
> > > > >
> > > > > {
> > > > >
> > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > >
> > > > >
> > > > >
> > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > to be placed in a lock.
> > > > >
> > > > >
> > > > >
> > > > > Example2::
> > > > >
> > > > >
> > > > >
> > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > >
> > > > > {
> > > > >
> > > > > lock(_Controller)
> > > > >
> > > > > {
> > > > >
> > > > > //Do stuff with your controller here
> > > > >
> > > > > }
> > > > >
> > > > > }
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > >
> > > > >
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > Behalf Of himykabibble
> > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > But perhaps a simple example:
> > > > >
> > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > >
> > > > > Some of the Button Click handlers also need to access things in
> > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > method in my dotNet "gasket" that handles all this.
> > > > >
> > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > vice-versa. Or perhaps there's another/better option?
> > > > >
> > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > functional, and their operation is straight-forward (though I note you are
> > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Hello Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > I would probably need to see some code to be much help.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > now,
> > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > thread? Or is there a better way?
> > > > > >
> > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > to
> > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > but
> > > > > > doesn't exit.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > but,
> > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > still
> > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > called. Not sure I understand why that's happening.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > rendering
> > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > can
> > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > update
> > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > controls. I already update the DROs more often than the other
> > > > > controls,
> > > > > > by
> > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > ticks.
> > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > getting
> > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > since
> > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > First off, you never want to have too many threads running,
> > > > > > technically
> > > > > > > > you
> > > > > > > > > can only have one run per core and anything after that is going to
> > > > > be
> > > > > > time
> > > > > > > > > slicing.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > HTML
> > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > earlier.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > loop
> > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > Within
> > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > and
> > > > > > > > > when that happens I update the less important items.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > the
> > > > > > > > DRO's
> > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > updated
> > > > > > > > > every ½ a second.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > >
> > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > updates
> > > > > > > > more
> > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > concurrency
> > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > just
> > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > now,
> > > > > > > > though
> > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > really
> > > > > > > > > need to be sped up.
> > > > > > > > >
> > > > > > > > > How would you do it?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > a
> > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > to
> > > > > > > > your
> > > > > > > > > > middle layer.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > control
> > > > > > > > > as
> > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > >
> > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > and
> > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > also
> > > > > > > > > allows
> > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > test
> > > > > > > > > the
> > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Gary,
> > > > > > > > > > >
> > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > assume
> > > > > > > > > > that
> > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > something
> > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Ray,
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > interact
> > > > > > > > > with
> > > > > > > > > > > the
> > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > can
> > > > > > > > > either
> > > > > > > > > > > use
> > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > using
> > > > > > > > > > > .net4.0
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > your
> > > > > > cpu
> > > > > > > > > > usage
> > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > comprehensive
> > > > > > > > use
> > > > > > > > > > > > model.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > easy
> > > > > > > > to
> > > > > > > > > > use
> > > > > > > > > > > to
> > > > > > > > > > > > and easy to read.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > your
> > > > > > > > > control
> > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > pseudo-example
> > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > parameter
> > > > > > > > > and
> > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > is
> > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > thread
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > else
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > invocation required
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > you
> > > > > > > > can
> > > > > > > > > > use
> > > > > > > > > > > > the above method like so::
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > >
> > > > > > > > > > > > //Example:
> > > > > > > > > > > >
> > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > >
> > > > > > > > > > > > }));
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > most
> > > > > > > > > parts,
> > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > For
> > > > > > > > > > > example,
> > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > execute a
> > > > > > > > > line
> > > > > > > > > > > of
> > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > running,
> > > > > > > > > the
> > > > > > > > > > > DROs
> > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > smooth
> > > > > > > > > > > updates
> > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > 100mSec,
> > > > > > > > > so
> > > > > > > > > > I
> > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > my
> > > > > > > > > code,
> > > > > > > > > > so
> > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > game.
> > > > > > > > > > > >
> > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > threads,
> > > > > > > > > > I've
> > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > question
> > > > > > > > > > > under
> > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > KMotionCNC,
> > > > > > > > > > they
> > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > But,
> > > > > > > > run
> > > > > > > > > > them
> > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > and
> > > > > > the
> > > > > > > > > > > threads
> > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > lunch.
> > > > > > > > > > KMotion
> > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > have
> > > > > > > > > > > terminated,
> > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > here's
> > > > > > the
> > > > > > > > > > > bizarre
> > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > open
> > > > > > > > the
> > > > > > > > > > app
> > > > > > > > > > > -
> > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > correctly! If
> > > > > > > > I
> > > > > > > > > > > just
> > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > work
> > > > > > > > > > > perfectly
> > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > message
> > > > > > > > > to
> > > > > > > > > > > the
> > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > MsgBox
> > > > > > > > > > does
> > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > thread
> > > > > > > > was
> > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > >
> > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > my
> > > > > > DSP
> > > > > > > > > > > programs
> > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > when
> > > > > > > > it
> > > > > > > > > > did
> > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > that's
> > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > here...
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3492 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad

Coming right up....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Ray,
>
> For clarity, please post your spindle.c files the bug tester is looking for so I can debug it.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> > Once you pull all those locks out ;).....
> >
> > Can you try something else for the sake of argument?
> >
> > Remove the use of the MainStatus and just get the axis values from the
> > interpreter and get your IO status from your KM_IO objects.
> >
> > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> >
> > Are you game?
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Tom,
> > >
> > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > >
> > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > >
> > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Guys,
> > > >  
> > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > >  
> > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > >  
> > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > >  
> > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > >  
> > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > >  
> > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > >  
> > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > >  
> > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > >
> > > > Anyway, just some thoughts..
> > > > Thanks
> > > > TK
> > > >  
> > > >  
> > > >
> > > > ________________________________
> > > > From: bradodarb <bradodarb@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > >
> > > > Hello Ray,
> > > >
> > > > Yes, lock every call.
> > > >
> > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > >
> > > > looking forward to hearing back your results.
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > >
> > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > with the only goal of finding your problem.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > access the controller object.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Example::
> > > > > >
> > > > > >
> > > > > >
> > > > > > lock(_Controller)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > >
> > > > > >
> > > > > >
> > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > to be placed in a lock.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Example2::
> > > > > >
> > > > > >
> > > > > >
> > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > lock(_Controller)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //Do stuff with your controller here
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > But perhaps a simple example:
> > > > > >
> > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > >
> > > > > > Some of the Button Click handlers also need to access things in
> > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > method in my dotNet "gasket" that handles all this.
> > > > > >
> > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > >
> > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Hello Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I would probably need to see some code to be much help.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > now,
> > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > thread? Or is there a better way?
> > > > > > >
> > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > to
> > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > but
> > > > > > > doesn't exit.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > but,
> > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > still
> > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > called. Not sure I understand why that's happening.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > rendering
> > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > can
> > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > update
> > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > controls,
> > > > > > > by
> > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > ticks.
> > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > getting
> > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > since
> > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > technically
> > > > > > > > > you
> > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > be
> > > > > > > time
> > > > > > > > > > slicing.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > HTML
> > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > earlier.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > loop
> > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > Within
> > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > and
> > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > the
> > > > > > > > > DRO's
> > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > updated
> > > > > > > > > > every ½ a second.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > >
> > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > updates
> > > > > > > > > more
> > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > concurrency
> > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > just
> > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > now,
> > > > > > > > > though
> > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > really
> > > > > > > > > > need to be sped up.
> > > > > > > > > >
> > > > > > > > > > How would you do it?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > a
> > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > to
> > > > > > > > > your
> > > > > > > > > > > middle layer.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > control
> > > > > > > > > > as
> > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > >
> > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > and
> > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > also
> > > > > > > > > > allows
> > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > test
> > > > > > > > > > the
> > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Gary,
> > > > > > > > > > > >
> > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > assume
> > > > > > > > > > > that
> > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > something
> > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > interact
> > > > > > > > > > with
> > > > > > > > > > > > the
> > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > can
> > > > > > > > > > either
> > > > > > > > > > > > use
> > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > using
> > > > > > > > > > > > .net4.0
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > your
> > > > > > > cpu
> > > > > > > > > > > usage
> > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > comprehensive
> > > > > > > > > use
> > > > > > > > > > > > > model.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > easy
> > > > > > > > > to
> > > > > > > > > > > use
> > > > > > > > > > > > to
> > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > your
> > > > > > > > > > control
> > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > pseudo-example
> > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > parameter
> > > > > > > > > > and
> > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > is
> > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > thread
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > else
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > invocation required
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > you
> > > > > > > > > can
> > > > > > > > > > > use
> > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Example:
> > > > > > > > > > > > >
> > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > >
> > > > > > > > > > > > > }));
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > most
> > > > > > > > > > parts,
> > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > For
> > > > > > > > > > > > example,
> > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > execute a
> > > > > > > > > > line
> > > > > > > > > > > > of
> > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > running,
> > > > > > > > > > the
> > > > > > > > > > > > DROs
> > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > smooth
> > > > > > > > > > > > updates
> > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > 100mSec,
> > > > > > > > > > so
> > > > > > > > > > > I
> > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > my
> > > > > > > > > > code,
> > > > > > > > > > > so
> > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > game.
> > > > > > > > > > > > >
> > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > threads,
> > > > > > > > > > > I've
> > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > question
> > > > > > > > > > > > under
> > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > KMotionCNC,
> > > > > > > > > > > they
> > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > But,
> > > > > > > > > run
> > > > > > > > > > > them
> > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > and
> > > > > > > the
> > > > > > > > > > > > threads
> > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > lunch.
> > > > > > > > > > > KMotion
> > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > have
> > > > > > > > > > > > terminated,
> > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > here's
> > > > > > > the
> > > > > > > > > > > > bizarre
> > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > open
> > > > > > > > > the
> > > > > > > > > > > app
> > > > > > > > > > > > -
> > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > correctly! If
> > > > > > > > > I
> > > > > > > > > > > > just
> > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > work
> > > > > > > > > > > > perfectly
> > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > message
> > > > > > > > > > to
> > > > > > > > > > > > the
> > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > MsgBox
> > > > > > > > > > > does
> > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > thread
> > > > > > > > > was
> > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > >
> > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > my
> > > > > > > DSP
> > > > > > > > > > > > programs
> > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > when
> > > > > > > > > it
> > > > > > > > > > > did
> > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > that's
> > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > here...
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3493 From: himykabibble Date: 1/26/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Posted as MyKFlopCPrograms.zip...

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad
>
> Coming right up....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> >
> > Ray,
> >
> > For clarity, please post your spindle.c files the bug tester is looking for so I can debug it.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > > Once you pull all those locks out ;).....
> > >
> > > Can you try something else for the sake of argument?
> > >
> > > Remove the use of the MainStatus and just get the axis values from the
> > > interpreter and get your IO status from your KM_IO objects.
> > >
> > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > >
> > > Are you game?
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > >
> > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > >
> > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Guys,
> > > > >  
> > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > >  
> > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > >  
> > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > >  
> > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > >  
> > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > >  
> > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > >  
> > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > >  
> > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > >
> > > > > Anyway, just some thoughts..
> > > > > Thanks
> > > > > TK
> > > > >  
> > > > >  
> > > > >
> > > > > ________________________________
> > > > > From: bradodarb <bradodarb@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > > Yes, lock every call.
> > > > >
> > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > >
> > > > > looking forward to hearing back your results.
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > >
> > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > with the only goal of finding your problem.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > access the controller object.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > to be placed in a lock.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example2::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Do stuff with your controller here
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > But perhaps a simple example:
> > > > > > >
> > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > >
> > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > >
> > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > >
> > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Hello Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I would probably need to see some code to be much help.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > now,
> > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > thread? Or is there a better way?
> > > > > > > >
> > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > to
> > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > but
> > > > > > > > doesn't exit.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > but,
> > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > still
> > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > rendering
> > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > can
> > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > update
> > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > controls,
> > > > > > > > by
> > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > ticks.
> > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > getting
> > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > since
> > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > technically
> > > > > > > > > > you
> > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > be
> > > > > > > > time
> > > > > > > > > > > slicing.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > HTML
> > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > earlier.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > loop
> > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > Within
> > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > and
> > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > the
> > > > > > > > > > DRO's
> > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > updated
> > > > > > > > > > > every ½ a second.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > >
> > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > updates
> > > > > > > > > > more
> > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > concurrency
> > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > just
> > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > now,
> > > > > > > > > > though
> > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > really
> > > > > > > > > > > need to be sped up.
> > > > > > > > > > >
> > > > > > > > > > > How would you do it?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > a
> > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > to
> > > > > > > > > > your
> > > > > > > > > > > > middle layer.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > control
> > > > > > > > > > > as
> > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > and
> > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > also
> > > > > > > > > > > allows
> > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > test
> > > > > > > > > > > the
> > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Gary,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > assume
> > > > > > > > > > > > that
> > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > something
> > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > interact
> > > > > > > > > > > with
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > can
> > > > > > > > > > > either
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > using
> > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > your
> > > > > > > > cpu
> > > > > > > > > > > > usage
> > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > comprehensive
> > > > > > > > > > use
> > > > > > > > > > > > > > model.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > easy
> > > > > > > > > > to
> > > > > > > > > > > > use
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > your
> > > > > > > > > > > control
> > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > parameter
> > > > > > > > > > > and
> > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > is
> > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > thread
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > else
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > you
> > > > > > > > > > can
> > > > > > > > > > > > use
> > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }));
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > most
> > > > > > > > > > > parts,
> > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > For
> > > > > > > > > > > > > example,
> > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > execute a
> > > > > > > > > > > line
> > > > > > > > > > > > > of
> > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > running,
> > > > > > > > > > > the
> > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > smooth
> > > > > > > > > > > > > updates
> > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > 100mSec,
> > > > > > > > > > > so
> > > > > > > > > > > > I
> > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > my
> > > > > > > > > > > code,
> > > > > > > > > > > > so
> > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > game.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > threads,
> > > > > > > > > > > > I've
> > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > question
> > > > > > > > > > > > > under
> > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > KMotionCNC,
> > > > > > > > > > > > they
> > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > But,
> > > > > > > > > > run
> > > > > > > > > > > > them
> > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > and
> > > > > > > > the
> > > > > > > > > > > > > threads
> > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > lunch.
> > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > have
> > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > here's
> > > > > > > > the
> > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > open
> > > > > > > > > > the
> > > > > > > > > > > > app
> > > > > > > > > > > > > -
> > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > correctly! If
> > > > > > > > > > I
> > > > > > > > > > > > > just
> > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > work
> > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > message
> > > > > > > > > > > to
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > MsgBox
> > > > > > > > > > > > does
> > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > thread
> > > > > > > > > > was
> > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > my
> > > > > > > > DSP
> > > > > > > > > > > > > programs
> > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > when
> > > > > > > > > > it
> > > > > > > > > > > > did
> > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > that's
> > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > here...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3495 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> > Once you pull all those locks out ;).....
> >
> > Can you try something else for the sake of argument?
> >
> > Remove the use of the MainStatus and just get the axis values from the
> > interpreter and get your IO status from your KM_IO objects.
> >
> > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> >
> > Are you game?
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Tom,
> > >
> > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > >
> > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > >
> > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Guys,
> > > >  
> > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > >  
> > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > >  
> > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > >  
> > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > >  
> > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > >  
> > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > >  
> > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > >  
> > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > >
> > > > Anyway, just some thoughts..
> > > > Thanks
> > > > TK
> > > >  
> > > >  
> > > >
> > > > ________________________________
> > > > From: bradodarb <bradodarb@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > >
> > > > Hello Ray,
> > > >
> > > > Yes, lock every call.
> > > >
> > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > >
> > > > looking forward to hearing back your results.
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > >
> > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > with the only goal of finding your problem.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > access the controller object.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Example::
> > > > > >
> > > > > >
> > > > > >
> > > > > > lock(_Controller)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > >
> > > > > >
> > > > > >
> > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > to be placed in a lock.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Example2::
> > > > > >
> > > > > >
> > > > > >
> > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > lock(_Controller)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //Do stuff with your controller here
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > But perhaps a simple example:
> > > > > >
> > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > >
> > > > > > Some of the Button Click handlers also need to access things in
> > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > method in my dotNet "gasket" that handles all this.
> > > > > >
> > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > >
> > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Hello Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I would probably need to see some code to be much help.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > now,
> > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > thread? Or is there a better way?
> > > > > > >
> > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > to
> > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > but
> > > > > > > doesn't exit.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > but,
> > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > still
> > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > called. Not sure I understand why that's happening.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > rendering
> > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > can
> > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > update
> > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > controls,
> > > > > > > by
> > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > ticks.
> > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > getting
> > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > since
> > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > technically
> > > > > > > > > you
> > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > be
> > > > > > > time
> > > > > > > > > > slicing.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > HTML
> > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > earlier.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > loop
> > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > Within
> > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > and
> > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > the
> > > > > > > > > DRO's
> > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > updated
> > > > > > > > > > every ½ a second.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > >
> > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > updates
> > > > > > > > > more
> > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > concurrency
> > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > just
> > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > now,
> > > > > > > > > though
> > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > really
> > > > > > > > > > need to be sped up.
> > > > > > > > > >
> > > > > > > > > > How would you do it?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > a
> > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > to
> > > > > > > > > your
> > > > > > > > > > > middle layer.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > control
> > > > > > > > > > as
> > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > >
> > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > and
> > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > also
> > > > > > > > > > allows
> > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > test
> > > > > > > > > > the
> > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Gary,
> > > > > > > > > > > >
> > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > assume
> > > > > > > > > > > that
> > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > something
> > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > interact
> > > > > > > > > > with
> > > > > > > > > > > > the
> > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > can
> > > > > > > > > > either
> > > > > > > > > > > > use
> > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > using
> > > > > > > > > > > > .net4.0
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > your
> > > > > > > cpu
> > > > > > > > > > > usage
> > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > comprehensive
> > > > > > > > > use
> > > > > > > > > > > > > model.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > easy
> > > > > > > > > to
> > > > > > > > > > > use
> > > > > > > > > > > > to
> > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > your
> > > > > > > > > > control
> > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > pseudo-example
> > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > parameter
> > > > > > > > > > and
> > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > is
> > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > thread
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > else
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > invocation required
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > you
> > > > > > > > > can
> > > > > > > > > > > use
> > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Example:
> > > > > > > > > > > > >
> > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > >
> > > > > > > > > > > > > }));
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > most
> > > > > > > > > > parts,
> > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > For
> > > > > > > > > > > > example,
> > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > execute a
> > > > > > > > > > line
> > > > > > > > > > > > of
> > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > running,
> > > > > > > > > > the
> > > > > > > > > > > > DROs
> > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > smooth
> > > > > > > > > > > > updates
> > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > 100mSec,
> > > > > > > > > > so
> > > > > > > > > > > I
> > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > my
> > > > > > > > > > code,
> > > > > > > > > > > so
> > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > game.
> > > > > > > > > > > > >
> > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > threads,
> > > > > > > > > > > I've
> > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > question
> > > > > > > > > > > > under
> > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > KMotionCNC,
> > > > > > > > > > > they
> > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > But,
> > > > > > > > > run
> > > > > > > > > > > them
> > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > and
> > > > > > > the
> > > > > > > > > > > > threads
> > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > lunch.
> > > > > > > > > > > KMotion
> > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > have
> > > > > > > > > > > > terminated,
> > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > here's
> > > > > > > the
> > > > > > > > > > > > bizarre
> > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > open
> > > > > > > > > the
> > > > > > > > > > > app
> > > > > > > > > > > > -
> > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > correctly! If
> > > > > > > > > I
> > > > > > > > > > > > just
> > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > work
> > > > > > > > > > > > perfectly
> > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > message
> > > > > > > > > > to
> > > > > > > > > > > > the
> > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > MsgBox
> > > > > > > > > > > does
> > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > thread
> > > > > > > > > was
> > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > >
> > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > my
> > > > > > > DSP
> > > > > > > > > > > > programs
> > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > when
> > > > > > > > > it
> > > > > > > > > > > did
> > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > that's
> > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > here...
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3496 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!

I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.

One new problem that has crept in:

I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.

Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.

Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > > Once you pull all those locks out ;).....
> > >
> > > Can you try something else for the sake of argument?
> > >
> > > Remove the use of the MainStatus and just get the axis values from the
> > > interpreter and get your IO status from your KM_IO objects.
> > >
> > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > >
> > > Are you game?
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > >
> > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > >
> > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Guys,
> > > > >  
> > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > >  
> > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > >  
> > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > >  
> > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > >  
> > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > >  
> > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > >  
> > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > >  
> > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > >
> > > > > Anyway, just some thoughts..
> > > > > Thanks
> > > > > TK
> > > > >  
> > > > >  
> > > > >
> > > > > ________________________________
> > > > > From: bradodarb <bradodarb@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > > Yes, lock every call.
> > > > >
> > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > >
> > > > > looking forward to hearing back your results.
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > >
> > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > with the only goal of finding your problem.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > access the controller object.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > to be placed in a lock.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example2::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Do stuff with your controller here
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > But perhaps a simple example:
> > > > > > >
> > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > >
> > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > >
> > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > >
> > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Hello Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I would probably need to see some code to be much help.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > now,
> > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > thread? Or is there a better way?
> > > > > > > >
> > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > to
> > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > but
> > > > > > > > doesn't exit.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > but,
> > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > still
> > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > rendering
> > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > can
> > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > update
> > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > controls,
> > > > > > > > by
> > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > ticks.
> > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > getting
> > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > since
> > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > technically
> > > > > > > > > > you
> > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > be
> > > > > > > > time
> > > > > > > > > > > slicing.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > HTML
> > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > earlier.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > loop
> > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > Within
> > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > and
> > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > the
> > > > > > > > > > DRO's
> > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > updated
> > > > > > > > > > > every ½ a second.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > >
> > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > updates
> > > > > > > > > > more
> > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > concurrency
> > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > just
> > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > now,
> > > > > > > > > > though
> > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > really
> > > > > > > > > > > need to be sped up.
> > > > > > > > > > >
> > > > > > > > > > > How would you do it?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > a
> > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > to
> > > > > > > > > > your
> > > > > > > > > > > > middle layer.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > control
> > > > > > > > > > > as
> > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > and
> > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > also
> > > > > > > > > > > allows
> > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > test
> > > > > > > > > > > the
> > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Gary,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > assume
> > > > > > > > > > > > that
> > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > something
> > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > interact
> > > > > > > > > > > with
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > can
> > > > > > > > > > > either
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > using
> > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > your
> > > > > > > > cpu
> > > > > > > > > > > > usage
> > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > comprehensive
> > > > > > > > > > use
> > > > > > > > > > > > > > model.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > easy
> > > > > > > > > > to
> > > > > > > > > > > > use
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > your
> > > > > > > > > > > control
> > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > parameter
> > > > > > > > > > > and
> > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > is
> > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > thread
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > else
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > you
> > > > > > > > > > can
> > > > > > > > > > > > use
> > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }));
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > most
> > > > > > > > > > > parts,
> > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > For
> > > > > > > > > > > > > example,
> > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > execute a
> > > > > > > > > > > line
> > > > > > > > > > > > > of
> > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > running,
> > > > > > > > > > > the
> > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > smooth
> > > > > > > > > > > > > updates
> > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > 100mSec,
> > > > > > > > > > > so
> > > > > > > > > > > > I
> > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > my
> > > > > > > > > > > code,
> > > > > > > > > > > > so
> > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > game.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > threads,
> > > > > > > > > > > > I've
> > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > question
> > > > > > > > > > > > > under
> > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > KMotionCNC,
> > > > > > > > > > > > they
> > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > But,
> > > > > > > > > > run
> > > > > > > > > > > > them
> > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > and
> > > > > > > > the
> > > > > > > > > > > > > threads
> > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > lunch.
> > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > have
> > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > here's
> > > > > > > > the
> > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > open
> > > > > > > > > > the
> > > > > > > > > > > > app
> > > > > > > > > > > > > -
> > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > correctly! If
> > > > > > > > > > I
> > > > > > > > > > > > > just
> > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > work
> > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > message
> > > > > > > > > > > to
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > MsgBox
> > > > > > > > > > > > does
> > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > thread
> > > > > > > > > > was
> > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > my
> > > > > > > > DSP
> > > > > > > > > > > > > programs
> > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > when
> > > > > > > > > > it
> > > > > > > > > > > > did
> > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > that's
> > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > here...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3498 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
All is not entirely well just yet. If I start my app, then start KMotion, and run a DSP program with printfs, it works fine. If I exit my app, then re-start it, I can sometimes no longer do printfs. No errors or complaints of any kind from KMotion, and no disconnects, but KMotion seems no longer able to control the board - I can't stop or start threads through the C Program dialog. Re-starting KMotion, leaving my app running, gets things working again.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
>
> I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
>
> One new problem that has crept in:
>
> I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
>
> Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
>
> Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > > Once you pull all those locks out ;).....
> > > >
> > > > Can you try something else for the sake of argument?
> > > >
> > > > Remove the use of the MainStatus and just get the axis values from the
> > > > interpreter and get your IO status from your KM_IO objects.
> > > >
> > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > >
> > > > Are you game?
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Tom,
> > > > >
> > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > >
> > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > >
> > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Guys,
> > > > > >  
> > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > >  
> > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > >  
> > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > >  
> > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > >  
> > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > > >  
> > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > > >  
> > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > >  
> > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > >
> > > > > > Anyway, just some thoughts..
> > > > > > Thanks
> > > > > > TK
> > > > > >  
> > > > > >  
> > > > > >
> > > > > > ________________________________
> > > > > > From: bradodarb <bradodarb@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > >
> > > > > > Hello Ray,
> > > > > >
> > > > > > Yes, lock every call.
> > > > > >
> > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > >
> > > > > > looking forward to hearing back your results.
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > >
> > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > with the only goal of finding your problem.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > access the controller object.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > to be placed in a lock.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example2::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > //Do stuff with your controller here
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > But perhaps a simple example:
> > > > > > > >
> > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > >
> > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > >
> > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > >
> > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Hello Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > now,
> > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > thread? Or is there a better way?
> > > > > > > > >
> > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > to
> > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > but
> > > > > > > > > doesn't exit.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > but,
> > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > still
> > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > rendering
> > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > can
> > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > update
> > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > controls,
> > > > > > > > > by
> > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > ticks.
> > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > getting
> > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > since
> > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > technically
> > > > > > > > > > > you
> > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > be
> > > > > > > > > time
> > > > > > > > > > > > slicing.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > HTML
> > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > earlier.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > loop
> > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > Within
> > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > and
> > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > the
> > > > > > > > > > > DRO's
> > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > > updated
> > > > > > > > > > > > every ½ a second.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > updates
> > > > > > > > > > > more
> > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > concurrency
> > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > just
> > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > now,
> > > > > > > > > > > though
> > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > really
> > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > >
> > > > > > > > > > > > How would you do it?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > a
> > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > to
> > > > > > > > > > > your
> > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > control
> > > > > > > > > > > > as
> > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > and
> > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > also
> > > > > > > > > > > > allows
> > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > test
> > > > > > > > > > > > the
> > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > assume
> > > > > > > > > > > > > that
> > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > something
> > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > interact
> > > > > > > > > > > > with
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > can
> > > > > > > > > > > > either
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > using
> > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > your
> > > > > > > > > cpu
> > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > comprehensive
> > > > > > > > > > > use
> > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > easy
> > > > > > > > > > > to
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > your
> > > > > > > > > > > > control
> > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > parameter
> > > > > > > > > > > > and
> > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > is
> > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > you
> > > > > > > > > > > can
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > most
> > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > For
> > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > execute a
> > > > > > > > > > > > line
> > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > running,
> > > > > > > > > > > > the
> > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > smooth
> > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > 100mSec,
> > > > > > > > > > > > so
> > > > > > > > > > > > > I
> > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > my
> > > > > > > > > > > > code,
> > > > > > > > > > > > > so
> > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > game.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > threads,
> > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > question
> > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > they
> > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > But,
> > > > > > > > > > > run
> > > > > > > > > > > > > them
> > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > and
> > > > > > > > > the
> > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > lunch.
> > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > have
> > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > here's
> > > > > > > > > the
> > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > open
> > > > > > > > > > > the
> > > > > > > > > > > > > app
> > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > correctly! If
> > > > > > > > > > > I
> > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > work
> > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > message
> > > > > > > > > > > > to
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > MsgBox
> > > > > > > > > > > > > does
> > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > thread
> > > > > > > > > > > was
> > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > my
> > > > > > > > > DSP
> > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > when
> > > > > > > > > > > it
> > > > > > > > > > > > > did
> > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > that's
> > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > here...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3499 From: Tom Kerekes Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.  It should be possible to get that MainStatus function working reliably.  I will try to find time to look at it soon.  I'm currently trying to get the Error Callbacks working.
 
Regards
TK
 

Group: DynoMotion Message: 3500 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom,

Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.  It should be possible to get that MainStatus function working reliably.  I will try to find time to look at it soon.  I'm currently trying to get the Error Callbacks working.
>  
> Regards
> TK
>  
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Friday, January 27, 2012 8:54 AM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> Brad,
>
> OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
>
> I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
>
> One new problem that has crept in:
>
> I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
>
> Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
>
> Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > > Once you pull all those locks out ;).....
> > > >
> > > > Can you try something else for the sake of argument?
> > > >
> > > > Remove the use of the MainStatus and just get the axis values from the
> > > > interpreter and get your IO status from your KM_IO objects.
> > > >
> > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > >
> > > > Are you game?
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Tom,
> > > > >
> > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > >
> > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > >
> > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Guys,
> > > > > >  
> > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > >  
> > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > >  
> > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > >  
> > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > >  
> > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > > >  
> > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > > >  
> > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > >  
> > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > >
> > > > > > Anyway, just some thoughts..
> > > > > > Thanks
> > > > > > TK
> > > > > >  
> > > > > >  
> > > > > >
> > > > > > ________________________________
> > > > > > From: bradodarb <bradodarb@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > >
> > > > > > Hello Ray,
> > > > > >
> > > > > > Yes, lock every call.
> > > > > >
> > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > >
> > > > > > looking forward to hearing back your results.
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > >
> > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > with the only goal of finding your problem.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > access the controller object.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > to be placed in a lock.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example2::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > //Do stuff with your controller here
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > But perhaps a simple example:
> > > > > > > >
> > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > >
> > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > >
> > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > >
> > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Hello Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > now,
> > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > thread? Or is there a better way?
> > > > > > > > >
> > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > to
> > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > but
> > > > > > > > > doesn't exit.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > but,
> > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > still
> > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > rendering
> > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > can
> > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > update
> > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > controls,
> > > > > > > > > by
> > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > ticks.
> > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > getting
> > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > since
> > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > technically
> > > > > > > > > > > you
> > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > be
> > > > > > > > > time
> > > > > > > > > > > > slicing.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > HTML
> > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > earlier.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > loop
> > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > Within
> > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > and
> > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > the
> > > > > > > > > > > DRO's
> > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > > updated
> > > > > > > > > > > > every ½ a second.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > updates
> > > > > > > > > > > more
> > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > concurrency
> > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > just
> > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > now,
> > > > > > > > > > > though
> > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > really
> > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > >
> > > > > > > > > > > > How would you do it?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > a
> > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > to
> > > > > > > > > > > your
> > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > control
> > > > > > > > > > > > as
> > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > and
> > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > also
> > > > > > > > > > > > allows
> > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > test
> > > > > > > > > > > > the
> > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > assume
> > > > > > > > > > > > > that
> > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > something
> > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > interact
> > > > > > > > > > > > with
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > can
> > > > > > > > > > > > either
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > using
> > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > your
> > > > > > > > > cpu
> > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > comprehensive
> > > > > > > > > > > use
> > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > easy
> > > > > > > > > > > to
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > your
> > > > > > > > > > > > control
> > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > parameter
> > > > > > > > > > > > and
> > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > is
> > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > you
> > > > > > > > > > > can
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > most
> > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > For
> > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > execute a
> > > > > > > > > > > > line
> > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > running,
> > > > > > > > > > > > the
> > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > smooth
> > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > 100mSec,
> > > > > > > > > > > > so
> > > > > > > > > > > > > I
> > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > my
> > > > > > > > > > > > code,
> > > > > > > > > > > > > so
> > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > game.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > threads,
> > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > question
> > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > they
> > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > But,
> > > > > > > > > > > run
> > > > > > > > > > > > > them
> > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > and
> > > > > > > > > the
> > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > lunch.
> > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > have
> > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > here's
> > > > > > > > > the
> > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > open
> > > > > > > > > > > the
> > > > > > > > > > > > > app
> > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > correctly! If
> > > > > > > > > > > I
> > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > work
> > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > message
> > > > > > > > > > > > to
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > MsgBox
> > > > > > > > > > > > > does
> > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > thread
> > > > > > > > > > > was
> > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > my
> > > > > > > > > DSP
> > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > when
> > > > > > > > > > > it
> > > > > > > > > > > > > did
> > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > that's
> > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > here...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3501 From: Tom Kerekes Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
 
TK

Group: DynoMotion Message: 3502 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.

I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
>  
> TK
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Friday, January 27, 2012 9:55 AM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> Tom,
>
> Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.  It should be possible to get that MainStatus function working reliably.  I will try to find time to look at it soon.  I'm currently trying to get the Error Callbacks working.
> >  
> > Regards
> > TK
> >  
> >
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Friday, January 27, 2012 8:54 AM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> > Brad,
> >
> > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> >
> > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> >
> > One new problem that has crept in:
> >
> > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> >
> > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> >
> > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > >
> > > > > Ray,
> > > > >
> > > > >
> > > > > Once you pull all those locks out ;).....
> > > > >
> > > > > Can you try something else for the sake of argument?
> > > > >
> > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > interpreter and get your IO status from your KM_IO objects.
> > > > >
> > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > >
> > > > > Are you game?
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Tom,
> > > > > >
> > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > >
> > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > >
> > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Guys,
> > > > > > >  
> > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > >  
> > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > >  
> > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > >  
> > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > >  
> > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > > > >  
> > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > > > >  
> > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > >  
> > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > >
> > > > > > > Anyway, just some thoughts..
> > > > > > > Thanks
> > > > > > > TK
> > > > > > >  
> > > > > > >  
> > > > > > >
> > > > > > > ________________________________
> > > > > > > From: bradodarb <bradodarb@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > >
> > > > > > > Hello Ray,
> > > > > > >
> > > > > > > Yes, lock every call.
> > > > > > >
> > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > >
> > > > > > > looking forward to hearing back your results.
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > >
> > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > with the only goal of finding your problem.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > access the controller object.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Example::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > lock(_Controller)
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > to be placed in a lock.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Example2::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > lock(_Controller)
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > //Do stuff with your controller here
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > But perhaps a simple example:
> > > > > > > > >
> > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > >
> > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > >
> > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > >
> > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hello Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > now,
> > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > >
> > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > to
> > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > but
> > > > > > > > > > doesn't exit.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > but,
> > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > still
> > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > rendering
> > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > can
> > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > update
> > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > controls,
> > > > > > > > > > by
> > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > ticks.
> > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > getting
> > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > since
> > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > technically
> > > > > > > > > > > > you
> > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > be
> > > > > > > > > > time
> > > > > > > > > > > > > slicing.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > HTML
> > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > earlier.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > loop
> > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > Within
> > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > and
> > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > the
> > > > > > > > > > > > DRO's
> > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > > > updated
> > > > > > > > > > > > > every ½ a second.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > updates
> > > > > > > > > > > > more
> > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > concurrency
> > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > just
> > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > now,
> > > > > > > > > > > > though
> > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > really
> > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > >
> > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > a
> > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > to
> > > > > > > > > > > > your
> > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > control
> > > > > > > > > > > > > as
> > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > and
> > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > also
> > > > > > > > > > > > > allows
> > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > test
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > assume
> > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > something
> > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > interact
> > > > > > > > > > > > > with
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > can
> > > > > > > > > > > > > either
> > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > using
> > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > your
> > > > > > > > > > cpu
> > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > comprehensive
> > > > > > > > > > > > use
> > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > easy
> > > > > > > > > > > > to
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > your
> > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > parameter
> > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > is
> > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > you
> > > > > > > > > > > > can
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > most
> > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > For
> > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > execute a
> > > > > > > > > > > > > line
> > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > running,
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > smooth
> > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > 100mSec,
> > > > > > > > > > > > > so
> > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > my
> > > > > > > > > > > > > code,
> > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > game.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > threads,
> > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > question
> > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > But,
> > > > > > > > > > > > run
> > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > and
> > > > > > > > > > the
> > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > lunch.
> > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > have
> > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > here's
> > > > > > > > > > the
> > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > open
> > > > > > > > > > > > the
> > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > correctly! If
> > > > > > > > > > > > I
> > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > work
> > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > message
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > thread
> > > > > > > > > > > > was
> > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > my
> > > > > > > > > > DSP
> > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > when
> > > > > > > > > > > > it
> > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > here...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3503 From: Tom Kerekes Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
Are you using the KLP low pass coordinated motion smoothing?
 
Regards
TK

Group: DynoMotion Message: 3504 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom,

Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> Are you using the KLP low pass coordinated motion smoothing?
>  
> Regards
> TK
>
>
> ________________________________
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Friday, January 27, 2012 11:51 AM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
>
> I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> >  
> > TK
> >
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Friday, January 27, 2012 9:55 AM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> > Tom,
> >
> > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.  It should be possible to get that MainStatus function working reliably.  I will try to find time to look at it soon.  I'm currently trying to get the Error Callbacks working.
> > >  
> > > Regards
> > > TK
> > >  
> > >
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Friday, January 27, 2012 8:54 AM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > Brad,
> > >
> > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > >
> > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > >
> > > One new problem that has crept in:
> > >
> > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > >
> > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > >
> > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > >
> > > > > > Ray,
> > > > > >
> > > > > >
> > > > > > Once you pull all those locks out ;).....
> > > > > >
> > > > > > Can you try something else for the sake of argument?
> > > > > >
> > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > >
> > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > >
> > > > > > Are you game?
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Tom,
> > > > > > >
> > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > >
> > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > >
> > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Guys,
> > > > > > > > ÃÆ'‚ 
> > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'‚  Multiple threads only help speed things upÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > >
> > > > > > > > Anyway, just some thoughts..
> > > > > > > > Thanks
> > > > > > > > TK
> > > > > > > > ÃÆ'‚ 
> > > > > > > > ÃÆ'‚ 
> > > > > > > >
> > > > > > > > ________________________________
> > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > > ÃÆ'‚ 
> > > > > > > >
> > > > > > > > Hello Ray,
> > > > > > > >
> > > > > > > > Yes, lock every call.
> > > > > > > >
> > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > >
> > > > > > > > looking forward to hearing back your results.
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > >
> > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > access the controller object.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Example::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > lock(_Controller)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > to be placed in a lock.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Example2::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'¢â‚¬Â¦.)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > lock(_Controller)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'¢â‚¬Â¦.
> > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > But perhaps a simple example:
> > > > > > > > > >
> > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > >
> > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > >
> > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > >
> > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hello Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > now,
> > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > >
> > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > to
> > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > but
> > > > > > > > > > > doesn't exit.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > but,
> > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > still
> > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > rendering
> > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > can
> > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > update
> > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > controls,
> > > > > > > > > > > by
> > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > ticks.
> > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > getting
> > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > since
> > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > technically
> > > > > > > > > > > > > you
> > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > be
> > > > > > > > > > > time
> > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > HTML
> > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > loop
> > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > Within
> > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > and
> > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > the
> > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'¢â‚¬Â¦ get
> > > > > > > > > > > > > updated
> > > > > > > > > > > > > > every ÃÆ'‚½ a second.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > updates
> > > > > > > > > > > > > more
> > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > concurrency
> > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > just
> > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > now,
> > > > > > > > > > > > > though
> > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > really
> > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > a
> > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > to
> > > > > > > > > > > > > your
> > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > control
> > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > and
> > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > also
> > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > test
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > something
> > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > interact
> > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > can
> > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > using
> > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > your
> > > > > > > > > > > cpu
> > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > comprehensive
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > easy
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > your
> > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > parameter
> > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > is
> > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > you
> > > > > > > > > > > > > can
> > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > most
> > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > For
> > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > execute a
> > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > running,
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > my
> > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > game.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > threads,
> > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > But,
> > > > > > > > > > > > > run
> > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > and
> > > > > > > > > > > the
> > > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > > lunch.
> > > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > > have
> > > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > > here's
> > > > > > > > > > > the
> > > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > > open
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > > correctly! If
> > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > > work
> > > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > > message
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > > thread
> > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > > my
> > > > > > > > > > > DSP
> > > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > > when
> > > > > > > > > > > > > it
> > > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > > here...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3505 From: Tom Kerekes Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
That is something relatively new and can only be set via C code as shown below:
 
double Tau = 0.001; // seconds for Low Pass Filter Time Constant
KLP = exp(-TIMEBASE/Tau);
printf("Tau=%f KLP=%f\n",Tau,KLP);
 
It is described in the latter half of this document
 
 
The default value of KLP is zero which is what is needed to eliminate any smoothing.
 
TK
 
 
Group: DynoMotion Message: 3507 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom,

OK, not using that.

I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> That is something relatively new and can only be set via C code as shown below:
>  
> double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> KLP = exp(-TIMEBASE/Tau);
> printf("Tau=%f KLP=%f\n",Tau,KLP);
>  
> It is described in the latter half of this document
>  
> http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
>  
> The default value of KLP is zero which is what is needed to eliminate any smoothing.
>  
> TK
>  
>  
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Friday, January 27, 2012 12:22 PM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> Tom,
>
> Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > Are you using the KLP low pass coordinated motion smoothing?
> >  
> > Regards
> > TK
> >
> >
> > ________________________________
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Friday, January 27, 2012 11:51 AM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> >
> > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > >  
> > > TK
> > >
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Friday, January 27, 2012 9:55 AM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > Tom,
> > >
> > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Ray,
> > > > ÃÆ'‚ 
> > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > ÃÆ'‚ 
> > > > Regards
> > > > TK
> > > > ÃÆ'‚ 
> > > >
> > > > From: himykabibble <jagboy@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > > ÃÆ'‚ 
> > > > Brad,
> > > >
> > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > >
> > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > >
> > > > One new problem that has crept in:
> > > >
> > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > >
> > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > >
> > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > > Once you pull all those locks out ;).....
> > > > > > >
> > > > > > > Can you try something else for the sake of argument?
> > > > > > >
> > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > >
> > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > >
> > > > > > > Are you game?
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Tom,
> > > > > > > >
> > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > >
> > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > >
> > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Guys,
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > >
> > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > Thanks
> > > > > > > > > TK
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > >
> > > > > > > > > ________________________________
> > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > >
> > > > > > > > > Hello Ray,
> > > > > > > > >
> > > > > > > > > Yes, lock every call.
> > > > > > > > >
> > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > >
> > > > > > > > > looking forward to hearing back your results.
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > >
> > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > access the controller object.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Example::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > lock(_Controller)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Example2::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > lock(_Controller)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > >
> > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > >
> > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > >
> > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > >
> > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > now,
> > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > >
> > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > to
> > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > but
> > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > but,
> > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > still
> > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > rendering
> > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > can
> > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > update
> > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > controls,
> > > > > > > > > > > > by
> > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > getting
> > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > since
> > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > technically
> > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > be
> > > > > > > > > > > > time
> > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > loop
> > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > and
> > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > the
> > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦ get
> > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > every ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > updates
> > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > just
> > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > now,
> > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > really
> > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > a
> > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > to
> > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > and
> > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > also
> > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > test
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > interact
> > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > can
> > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > your
> > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > easy
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > your
> > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > you
> > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > most
> > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > execute a
> > > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > > running,
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > > my
> > > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > > game.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > > threads,
> > > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > > But,
> > > > > > > > > > > > > > run
> > > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > > and
> > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > > > lunch.
> > > > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > > > have
> > > > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > > > here's
> > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > > > open
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > > > correctly! If
> > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > > > work
> > > > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > > > message
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > > > thread
> > > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > > > my
> > > > > > > > > > > > DSP
> > > > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > > > when
> > > > > > > > > > > > > > it
> > > > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > > > here...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3515 From: himykabibble Date: 1/27/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!

I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.

The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.

I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!

Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Tom,
>
> OK, not using that.
>
> I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > That is something relatively new and can only be set via C code as shown below:
> >  
> > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > KLP = exp(-TIMEBASE/Tau);
> > printf("Tau=%f KLP=%f\n",Tau,KLP);
> >  
> > It is described in the latter half of this document
> >  
> > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> >  
> > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> >  
> > TK
> >  
> >  
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Friday, January 27, 2012 12:22 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> > Tom,
> >
> > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > Are you using the KLP low pass coordinated motion smoothing?
> > >  
> > > Regards
> > > TK
> > >
> > >
> > > ________________________________
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Friday, January 27, 2012 11:51 AM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > >
> > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Ray,
> > > >  
> > > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > >  
> > > > TK
> > > >
> > > > From: himykabibble <jagboy@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > > Tom,
> > > >
> > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > > ÃÆ'‚ 
> > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > ÃÆ'‚ 
> > > > > Regards
> > > > > TK
> > > > > ÃÆ'‚ 
> > > > >
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > > ÃÆ'‚ 
> > > > > Brad,
> > > > >
> > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > >
> > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > >
> > > > > One new problem that has crept in:
> > > > >
> > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > >
> > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > >
> > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > > Once you pull all those locks out ;).....
> > > > > > > >
> > > > > > > > Can you try something else for the sake of argument?
> > > > > > > >
> > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > >
> > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > >
> > > > > > > > Are you game?
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Tom,
> > > > > > > > >
> > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > >
> > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > >
> > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Guys,
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > >
> > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > Thanks
> > > > > > > > > > TK
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > >
> > > > > > > > > > ________________________________
> > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > >
> > > > > > > > > > Hello Ray,
> > > > > > > > > >
> > > > > > > > > > Yes, lock every call.
> > > > > > > > > >
> > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > >
> > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > >
> > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Ray,
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > access the controller object.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Example::
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Example2::
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > >
> > > > > > > > > > > > {
> > > > > > > > > > > >
> > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > >
> > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > >
> > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > >
> > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > >
> > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > now,
> > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > to
> > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > but
> > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > but,
> > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > still
> > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > can
> > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > update
> > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > controls,
> > > > > > > > > > > > > by
> > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > since
> > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > be
> > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > the
> > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦ get
> > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > every ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > updates
> > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > now,
> > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > to
> > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > your
> > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > your
> > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > you
> > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > > most
> > > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > > execute a
> > > > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > > > running,
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > > > my
> > > > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > > > game.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > > > threads,
> > > > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > > > But,
> > > > > > > > > > > > > > > run
> > > > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > > > and
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > > > > lunch.
> > > > > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > > > > have
> > > > > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > > > > here's
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > > > > open
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > > > > correctly! If
> > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > > > > work
> > > > > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > > > > message
> > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > > > > my
> > > > > > > > > > > > > DSP
> > > > > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > > > > when
> > > > > > > > > > > > > > > it
> > > > > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > > > > here...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3524 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad/Tom,

I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.

Here's the code on my side:

public String[] GatherHex(int offset, int words)
{
String[] ret = new String[words];
int lines = (words + 7) / 8;
String[] s = new String[lines];

WaitToken();
KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
for (int i = 0; i < lines; i++)
KMController.ReadLineTimout(ref s[i], 500);
ReleaseToken();
int thisword = 0;
foreach (String t in s)
{
foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
{
ret[thisword] = u;
if (++thisword == words)
break;
}
}
return ret;
}


Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
>
> I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
>
> The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
>
> I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
>
> Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Tom,
> >
> > OK, not using that.
> >
> > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > That is something relatively new and can only be set via C code as shown below:
> > >  
> > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > KLP = exp(-TIMEBASE/Tau);
> > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > >  
> > > It is described in the latter half of this document
> > >  
> > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > >  
> > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > >  
> > > TK
> > >  
> > >  
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Friday, January 27, 2012 12:22 PM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > Tom,
> > >
> > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Ray,
> > > >  
> > > > Are you using the KLP low pass coordinated motion smoothing?
> > > >  
> > > > Regards
> > > > TK
> > > >
> > > >
> > > > ________________________________
> > > > From: himykabibble <jagboy@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > >
> > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > >  
> > > > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > >  
> > > > > TK
> > > > >
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > > Tom,
> > > > >
> > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > > ÃÆ'‚ 
> > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > ÃÆ'‚ 
> > > > > > Regards
> > > > > > TK
> > > > > > ÃÆ'‚ 
> > > > > >
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > > ÃÆ'‚ 
> > > > > > Brad,
> > > > > >
> > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > >
> > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > >
> > > > > > One new problem that has crept in:
> > > > > >
> > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > >
> > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > >
> > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > >
> > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > >
> > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > >
> > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > >
> > > > > > > > > Are you game?
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Tom,
> > > > > > > > > >
> > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > >
> > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > >
> > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Guys,
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > >
> > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > Thanks
> > > > > > > > > > > TK
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > >
> > > > > > > > > > > ________________________________
> > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > >
> > > > > > > > > > > Hello Ray,
> > > > > > > > > > >
> > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > >
> > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > >
> > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > >
> > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Example::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Example2::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > >
> > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > >
> > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > >
> > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > now,
> > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > but
> > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > but,
> > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > still
> > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > be
> > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > every ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > your
> > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > > > most
> > > > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > > > execute a
> > > > > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > > > > running,
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > > > > my
> > > > > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > > > > game.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > > > > threads,
> > > > > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > > > > But,
> > > > > > > > > > > > > > > > run
> > > > > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > > > > and
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > > > > > lunch.
> > > > > > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > > > > > have
> > > > > > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > > > > > here's
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > > > > > open
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > > > > > correctly! If
> > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > > > > > work
> > > > > > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > > > > > message
> > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > > > > > my
> > > > > > > > > > > > > > DSP
> > > > > > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > > > > > when
> > > > > > > > > > > > > > > > it
> > > > > > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > > > > > here...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3525 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.

main()
{
KM_Controller KM = new KM_Controller();
Thread.Sleep(1000);
GatherHex(0, 8);
}

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad/Tom,
>
> I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
>
> Here's the code on my side:
>
> public String[] GatherHex(int offset, int words)
> {
> String[] ret = new String[words];
> int lines = (words + 7) / 8;
> String[] s = new String[lines];
>
> WaitToken();
> KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> for (int i = 0; i < lines; i++)
> KMController.ReadLineTimout(ref s[i], 500);
> ReleaseToken();
> int thisword = 0;
> foreach (String t in s)
> {
> foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> {
> ret[thisword] = u;
> if (++thisword == words)
> break;
> }
> }
> return ret;
> }
>
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> >
> > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> >
> > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> >
> > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> >
> > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Tom,
> > >
> > > OK, not using that.
> > >
> > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Ray,
> > > >  
> > > > That is something relatively new and can only be set via C code as shown below:
> > > >  
> > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > KLP = exp(-TIMEBASE/Tau);
> > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > >  
> > > > It is described in the latter half of this document
> > > >  
> > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > >  
> > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > >  
> > > > TK
> > > >  
> > > >  
> > > > From: himykabibble <jagboy@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > > Tom,
> > > >
> > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > >  
> > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > >  
> > > > > Regards
> > > > > TK
> > > > >
> > > > >
> > > > > ________________________________
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > >
> > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > >  
> > > > > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > >  
> > > > > > TK
> > > > > >
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > > Tom,
> > > > > >
> > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > > ÃÆ'‚ 
> > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > ÃÆ'‚ 
> > > > > > > Regards
> > > > > > > TK
> > > > > > > ÃÆ'‚ 
> > > > > > >
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > > ÃÆ'‚ 
> > > > > > > Brad,
> > > > > > >
> > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > >
> > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > >
> > > > > > > One new problem that has crept in:
> > > > > > >
> > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > >
> > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > >
> > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > >
> > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > >
> > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > >
> > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > >
> > > > > > > > > > Are you game?
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Tom,
> > > > > > > > > > >
> > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > >
> > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > >
> > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > >
> > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > Thanks
> > > > > > > > > > > > TK
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > >
> > > > > > > > > > > > ________________________________
> > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > >
> > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > >
> > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > >
> > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > >
> > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > >
> > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > every ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > > > > most
> > > > > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > > > > execute a
> > > > > > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > > > > > running,
> > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > > > > > my
> > > > > > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > > > > > game.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > > > > > threads,
> > > > > > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > > > > > But,
> > > > > > > > > > > > > > > > > run
> > > > > > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > > > > > > lunch.
> > > > > > > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > > > > > > have
> > > > > > > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > > > > > > here's
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > > > > > > open
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > > > > > > correctly! If
> > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > > > > > > work
> > > > > > > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > > > > > > message
> > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > > > > > > my
> > > > > > > > > > > > > > > DSP
> > > > > > > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > > > > > > when
> > > > > > > > > > > > > > > > > it
> > > > > > > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > > > > > > here...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3526 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
>
> main()
> {
> KM_Controller KM = new KM_Controller();
> Thread.Sleep(1000);
> GatherHex(0, 8);
> }
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad/Tom,
> >
> > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> >
> > Here's the code on my side:
> >
> > public String[] GatherHex(int offset, int words)
> > {
> > String[] ret = new String[words];
> > int lines = (words + 7) / 8;
> > String[] s = new String[lines];
> >
> > WaitToken();
> > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > for (int i = 0; i < lines; i++)
> > KMController.ReadLineTimout(ref s[i], 500);
> > ReleaseToken();
> > int thisword = 0;
> > foreach (String t in s)
> > {
> > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > {
> > ret[thisword] = u;
> > if (++thisword == words)
> > break;
> > }
> > }
> > return ret;
> > }
> >
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > >
> > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > >
> > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > >
> > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > >
> > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > OK, not using that.
> > > >
> > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > >  
> > > > > That is something relatively new and can only be set via C code as shown below:
> > > > >  
> > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > >  
> > > > > It is described in the latter half of this document
> > > > >  
> > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > >  
> > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > >  
> > > > > TK
> > > > >  
> > > > >  
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > > Tom,
> > > > >
> > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > >  
> > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > >  
> > > > > > Regards
> > > > > > TK
> > > > > >
> > > > > >
> > > > > > ________________________________
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > >
> > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > >  
> > > > > > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > >  
> > > > > > > TK
> > > > > > >
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > > Tom,
> > > > > > >
> > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > > ÃÆ'‚ 
> > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Regards
> > > > > > > > TK
> > > > > > > > ÃÆ'‚ 
> > > > > > > >
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > >
> > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > >
> > > > > > > > One new problem that has crept in:
> > > > > > > >
> > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > >
> > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > >
> > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > >
> > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > >
> > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > >
> > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > >
> > > > > > > > > > > Are you game?
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > >
> > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > TK
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > >
> > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > >
> > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > > > > > most
> > > > > > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > > > > > execute a
> > > > > > > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > > > > > > running,
> > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > > > > > > my
> > > > > > > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > > > > > > game.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > > > > > > threads,
> > > > > > > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > > > > > > But,
> > > > > > > > > > > > > > > > > > run
> > > > > > > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > > > > > > > > lunch.
> > > > > > > > > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > > > > > > > > have
> > > > > > > > > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > > > > > > > > here's
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > > > > > > > > open
> > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > app
> > > > > > > > > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > > > > > > > > correctly! If
> > > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > > > > > > > > work
> > > > > > > > > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > > > > > > > > message
> > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > > > > > > > > MsgBox
> > > > > > > > > > > > > > > > > > > > does
> > > > > > > > > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > was
> > > > > > > > > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > > > > > > > > my
> > > > > > > > > > > > > > > > DSP
> > > > > > > > > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > > > > > > > > when
> > > > > > > > > > > > > > > > > > it
> > > > > > > > > > > > > > > > > > > > did
> > > > > > > > > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > > > > > > > > that's
> > > > > > > > > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > > > > > > > > here...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3527 From: Tom Kerekes Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
 
Regards
TK

Group: DynoMotion Message: 3528 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Tom,

 

#1Good, but I suggested the lock to make sure we weren’t trying to grab a token from multiple threads.  I think I understand that the token will be atomic and only be given to the calling thread but my thoughts were a lock will cause the next calling thread to wait until the other thread is done.

 

#2 A separate GUI update thread is advantageous here because updating the data is taking <100ms at some times.  If a timer is being used with say a 100ms interval and the task is taking 200ms then the GUI will be locked as the next timer ‘tick’ event will have been fired before the last was completed.

 

By having the updating on a separate thread, the update process can take however long as is needed and update every cycle.

 

#3 The Task Parallel library in .net 4.0 will distribute amongst cores when possible.

 

 

Not saying the above is set in stone gospel(except 3), but is where I was coming from.

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
Sent: Thursday, January 26, 2012 11:10 PM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Hi Guys,

 

I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.

 

Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.

 

#1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.

 

The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.

 

The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.

 

There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.

 

#2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.

 

#3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.


Anyway, just some thoughts..

Thanks

TK

 

 

From: bradodarb <bradodarb@...>
To: DynoMotion@yahoogroups.com
Sent: Thursday, January 26, 2012 8:46 PM
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Hello Ray,

Yes, lock every call.

MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.

looking forward to hearing back your results.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
>
> "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
>
> Regards,
> Ray L.
>
>
> --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> >
> > As far as your code goes, I would be looking with an non-judgmental eye and
> > with the only goal of finding your problem.
> >
> >
> >
> >
> >
> > Before that , you could try to surround any calls to the KM_Controller
> > instance with a lock clause. This will allow only one thread at a time to
> > access the controller object.
> >
> >
> >
> > Example::
> >
> >
> >
> > lock(_Controller)
> >
> > {
> >
> > var status = _Controller.WriteLineReadLine("Version");
> >
> >
> >
> > var status2 = _Controller.WriteLineReadLine("Version");
> >
> > }
> >
> >
> >
> > Basically, any function you are using the KM_Controller instance in may need
> > to be placed in a lock.
> >
> >
> >
> > Example2::
> >
> >
> >
> > Public void MyUpdatingOrCommandingFunction(args….)
> >
> > {
> >
> > lock(_Controller)
> >
> > {
> >
> > //Do stuff with your controller here
> >
> > }
> >
> > }
> >
> >
> >
> >
> >
> > Try this and let me know if it helps. It is making sense to me that the
> > KM_Controller is not Thread safe as it is maintaining pointer references….
> > I never ran into it on MM as it never accesses the GUI thread.
> >
> >
> >
> > -Brad Murry
> >
> > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > Behalf Of himykabibble
> > Sent: Thursday, January 26, 2012 9:14 PM
> > To: DynoMotion@yahoogroups.com
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Brad,
> >
> > I'd be happy to send you my code, if you promise not to laugh too hard....
> > But perhaps a simple example:
> >
> > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > current tool, spindle RPM, and a number of other things. Those are currently
> > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> >
> > Some of the Button Click handlers also need to access things in
> > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > method in my dotNet "gasket" that handles all this.
> >
> > So, My KM_Controller is currently getting called by both the UI thread, and
> > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > be better to have only one thread talking the KM_Controller? If so, should I
> > move all calls from the BackgroundWorker thread to the UI thread, or
> > vice-versa. Or perhaps there's another/better option?
> >
> > I looked through your HTML app code, but you don't seem to be dealing with
> > that problem yet, since it appears to me only the DROs are actually
> > functional, and their operation is straight-forward (though I note you are
> > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > Brad Murry <bradodarb@> wrote:
> > >
> > > Hello Ray,
> > >
> > >
> > >
> > > I would probably need to see some code to be much help.
> > >
> > >
> > >
> > > Brad Murry
> > >
> > >
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 8:57 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > clear on the right way to handle communications with dotNet. My UI update
> > > thread needs to access various dotNet data to create the updates. Right
> > now,
> > > I'm doing those accesses in the DoWork method, creating an object that
> > > contains the UI status, then tossing that over to the UI thread to update
> > > the controls. But, the UI thread also needs to access dotNet when things
> > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > thread? Or is there a better way?
> > >
> > > Right now, something I've done has made the hangs much worse. I'm getting
> > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > to
> > > get the BackgroundWorker thread to exit. It stops updating the display,
> > but
> > > doesn't exit.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > plagiarizing what you do in your HTML app. It was relatively painless,
> > but,
> > > surprisingly, didn't really make any perceptible difference in terms of
> > > display update performance. It also, not surprisingly, introduced a couple
> > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > still
> > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > called. Not sure I understand why that's happening.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > The only thing I will add at this point is try it and you will see.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > I will add that MM uses a multi-threading model, has a lot more
> > > rendering
> > > > > going on that a winforms app, also does openGL toolpath display and I
> > > can
> > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Nowadays any non-trivial app requires multi-threading.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -Brad
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > update
> > > > > time is getting the information from dotNet, not actually updating the
> > > > > controls. I already update the DROs more often than the other
> > controls,
> > > by
> > > > > just doing the DROs on every timer tick, and the others on alternate
> > > ticks.
> > > > > How will another thread improve performance, if the bottleneck is
> > > getting
> > > > > the update data (which comes primarily from MainStatus), particularly
> > > since
> > > > > I have to go through an invoke to modify each control?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > >
> > > > > > First off, you never want to have too many threads running,
> > > technically
> > > > > you
> > > > > > can only have one run per core and anything after that is going to
> > be
> > > time
> > > > > > slicing.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > HTML
> > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > earlier.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > loop
> > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > Within
> > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > and
> > > > > > when that happens I update the less important items.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Very basic setup that only uses one additional thread that updates
> > the
> > > > > DRO's
> > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > updated
> > > > > > every ½ a second.
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will re-upload my source so you can see how it works.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > >
> > > > > > I can see how I could use parallel threads to make the display
> > updates
> > > > > more
> > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > controls). I assume the wonders of .NET will deal with all the
> > > concurrency
> > > > > > issues that could create in accessing especially dotNet objects? I
> > > just
> > > > > > checked and my update loop is running only about 5X/second right
> > now,
> > > > > though
> > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > really
> > > > > > need to be sped up.
> > > > > >
> > > > > > How would you do it?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > a
> > > > > > > reference to a control you are using(best bet is the main window)
> > to
> > > > > your
> > > > > > > middle layer.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > control
> > > > > > as
> > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > >
> > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > and
> > > > > > > high-level. All communications passes through that layer, and it
> > > also
> > > > > > allows
> > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > test
> > > > > > the
> > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Who you calling Gary? ;)
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Clarify KM"gasket" please.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Gary,
> > > > > > > >
> > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > assume
> > > > > > > that
> > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > something
> > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would ditch the timer as well, using a service thread to
> > > interact
> > > > > > with
> > > > > > > > the
> > > > > > > > > kflop will be much smoother.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Instead of running your updates via your timer's callback you
> > > can
> > > > > > either
> > > > > > > > use
> > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > using
> > > > > > > > .net4.0
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Parallel tasks are best because the will automagically load
> > your
> > > cpu
> > > > > > > usage
> > > > > > > > > based on how many cores are available, etc.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Background workers are pretty easy to use and have a
> > > comprehensive
> > > > > use
> > > > > > > > > model.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > easy
> > > > > to
> > > > > > > use
> > > > > > > > to
> > > > > > > > > and easy to read.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > your
> > > > > > control
> > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > pseudo-example
> > > > > > > > > where I am using a common method that takes an Action as a
> > > parameter
> > > > > > and
> > > > > > > > > decides whether to invoke or not::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > is
> > > > > > > > > coming from a thread other than the GUI
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > thread
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > else
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > invocation required
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > In the updating method of whichever threading model you chose,
> > > you
> > > > > can
> > > > > > > use
> > > > > > > > > the above method like so::
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > >
> > > > > > > > > {
> > > > > > > > >
> > > > > > > > > //Put your control updating code here.
> > > > > > > > >
> > > > > > > > > //Example:
> > > > > > > > >
> > > > > > > > > lblXaxisDest.Text =
> > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > >
> > > > > > > > > }));
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > So, I've been exercising my app on the machine, and for the
> > most
> > > > > > parts,
> > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > For
> > > > > > > > example,
> > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > execute a
> > > > > > line
> > > > > > > > of
> > > > > > > > > G-code containing nothing more than a single comment. When
> > > running,
> > > > > > the
> > > > > > > > DROs
> > > > > > > > > update in significant increments, rather than the relatively
> > > smooth
> > > > > > > > updates
> > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > 100mSec,
> > > > > > so
> > > > > > > I
> > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > my
> > > > > > code,
> > > > > > > so
> > > > > > > > > none of this concerns me at all at this early stage of the
> > game.
> > > > > > > > >
> > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > threads,
> > > > > > > I've
> > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > question
> > > > > > > > under
> > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > KMotionCNC,
> > > > > > > they
> > > > > > > > > both execute correctly first time, every time, without fail.
> > > But,
> > > > > run
> > > > > > > them
> > > > > > > > > under my app, using the few lines of code posted last night,
> > and
> > > the
> > > > > > > > threads
> > > > > > > > > start, may, or may not, make the first move, then go out to
> > > lunch.
> > > > > > > KMotion
> > > > > > > > > confirms the threads remain running long after they should
> > have
> > > > > > > > terminated,
> > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > here's
> > > the
> > > > > > > > bizarre
> > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > open
> > > > > the
> > > > > > > app
> > > > > > > > -
> > > > > > > > > the thread immediately picks up and runs to completion
> > > correctly! If
> > > > > I
> > > > > > > > just
> > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > work
> > > > > > > > perfectly
> > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > message
> > > > > > to
> > > > > > > > the
> > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > MsgBox
> > > > > > > does
> > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > thread
> > > > > was
> > > > > > > > > launched from MY app!
> > > > > > > > >
> > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > my
> > > DSP
> > > > > > > > programs
> > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > when
> > > > > it
> > > > > > > did
> > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > that's
> > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > here...
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

 

Group: DynoMotion Message: 3529 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Ray,

 

Do you have the locking problem when no other applications that use the Kflop are running?(KMotion.exe, KMotionCNC.exe)?

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Friday, January 27, 2012 12:00 AM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Posted as MyKFlopCPrograms.zip...

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad
>
> Coming right up....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> >
> > Ray,
> >
> > For clarity, please post your spindle.c files the bug tester is looking for so I can debug it.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > > Once you pull all those locks out ;).....
> > >
> > > Can you try something else for the sake of argument?
> > >
> > > Remove the use of the MainStatus and just get the axis values from the
> > > interpreter and get your IO status from your KM_IO objects.
> > >
> > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > >
> > > Are you game?
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > >
> > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > >
> > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Guys,
> > > > >  
> > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > >  
> > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > >  
> > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > >  
> > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > >  
> > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > >  
> > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > >  
> > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > >  
> > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > >
> > > > > Anyway, just some thoughts..
> > > > > Thanks
> > > > > TK
> > > > >  
> > > > >  
> > > > >
> > > > > ________________________________
> > > > > From: bradodarb <bradodarb@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > > Yes, lock every call.
> > > > >
> > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > >
> > > > > looking forward to hearing back your results.
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > >
> > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > with the only goal of finding your problem.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > access the controller object.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > to be placed in a lock.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example2::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Do stuff with your controller here
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > But perhaps a simple example:
> > > > > > >
> > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > >
> > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > >
> > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > >
> > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Hello Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I would probably need to see some code to be much help.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > now,
> > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > thread? Or is there a better way?
> > > > > > > >
> > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > to
> > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > but
> > > > > > > > doesn't exit.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > but,
> > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > still
> > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > rendering
> > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > can
> > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > update
> > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > controls,
> > > > > > > > by
> > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > ticks.
> > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > getting
> > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > since
> > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > technically
> > > > > > > > > > you
> > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > be
> > > > > > > > time
> > > > > > > > > > > slicing.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > HTML
> > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > earlier.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > loop
> > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > Within
> > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > and
> > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > the
> > > > > > > > > > DRO's
> > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > updated
> > > > > > > > > > > every ½ a second.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > >
> > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > updates
> > > > > > > > > > more
> > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > concurrency
> > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > just
> > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > now,
> > > > > > > > > > though
> > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > really
> > > > > > > > > > > need to be sped up.
> > > > > > > > > > >
> > > > > > > > > > > How would you do it?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > a
> > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > to
> > > > > > > > > > your
> > > > > > > > > > > > middle layer.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > control
> > > > > > > > > > > as
> > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > and
> > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > also
> > > > > > > > > > > allows
> > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > test
> > > > > > > > > > > the
> > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Gary,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > assume
> > > > > > > > > > > > that
> > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > something
> > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > interact
> > > > > > > > > > > with
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > can
> > > > > > > > > > > either
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > using
> > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > your
> > > > > > > > cpu
> > > > > > > > > > > > usage
> > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > comprehensive
> > > > > > > > > > use
> > > > > > > > > > > > > > model.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > easy
> > > > > > > > > > to
> > > > > > > > > > > > use
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > your
> > > > > > > > > > > control
> > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > parameter
> > > > > > > > > > > and
> > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > is
> > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > thread
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > else
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > }
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > you
> > > > > > > > > > can
> > > > > > > > > > > > use
> > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3531 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Hello Ray,

 

Tool file is not really implemented, but I plan to for people who want to use it.

 

I never planned to use it so I created methods to populate the tool table programmatically. 

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Thursday, January 26, 2012 11:27 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Tom,

I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).

I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)

BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Guys,
>  
> I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
>  
> Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
>  
> #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
>  
> The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
>  
> The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
>  
> There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
>  
> #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
>  
> #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
>
> Anyway, just some thoughts..
> Thanks
> TK
>  
>  
>
> ________________________________
> From: bradodarb <bradodarb@...>
> To: DynoMotion@yahoogroups.com
> Sent: Thursday, January 26, 2012 8:46 PM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
>
> Hello Ray,
>
> Yes, lock every call.
>
> MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
>
> looking forward to hearing back your results.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> >
> > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> >
> > Regards,
> > Ray L.
> >
> >
> > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > with the only goal of finding your problem.
> > >
> > >
> > >
> > >
> > >
> > > Before that , you could try to surround any calls to the KM_Controller
> > > instance with a lock clause. This will allow only one thread at a time to
> > > access the controller object.
> > >
> > >
> > >
> > > Example::
> > >
> > >
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > var status = _Controller.WriteLineReadLine("Version");
> > >
> > >
> > >
> > > var status2 = _Controller.WriteLineReadLine("Version");
> > >
> > > }
> > >
> > >
> > >
> > > Basically, any function you are using the KM_Controller instance in may need
> > > to be placed in a lock.
> > >
> > >
> > >
> > > Example2::
> > >
> > >
> > >
> > > Public void MyUpdatingOrCommandingFunction(args….)
> > >
> > > {
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > //Do stuff with your controller here
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > Try this and let me know if it helps. It is making sense to me that the
> > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > I never ran into it on MM as it never accesses the GUI thread.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 9:14 PM
> > > To: DynoMotion@yahoogroups.com
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > But perhaps a simple example:
> > >
> > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > current tool, spindle RPM, and a number of other things. Those are currently
> > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > >
> > > Some of the Button Click handlers also need to access things in
> > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > method in my dotNet "gasket" that handles all this.
> > >
> > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > be better to have only one thread talking the KM_Controller? If so, should I
> > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > vice-versa. Or perhaps there's another/better option?
> > >
> > > I looked through your HTML app code, but you don't seem to be dealing with
> > > that problem yet, since it appears to me only the DROs are actually
> > > functional, and their operation is straight-forward (though I note you are
> > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Hello Ray,
> > > >
> > > >
> > > >
> > > > I would probably need to see some code to be much help.
> > > >
> > > >
> > > >
> > > > Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > clear on the right way to handle communications with dotNet. My UI update
> > > > thread needs to access various dotNet data to create the updates. Right
> > > now,
> > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > contains the UI status, then tossing that over to the UI thread to update
> > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > thread? Or is there a better way?
> > > >
> > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > to
> > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > but
> > > > doesn't exit.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > but,
> > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > display update performance. It also, not surprisingly, introduced a couple
> > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > still
> > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > called. Not sure I understand why that's happening.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > The only thing I will add at this point is try it and you will see.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > rendering
> > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > can
> > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > update
> > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > controls. I already update the DROs more often than the other
> > > controls,
> > > > by
> > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > ticks.
> > > > > > How will another thread improve performance, if the bottleneck is
> > > > getting
> > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > since
> > > > > > I have to go through an invoke to modify each control?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > >
> > > > > > > First off, you never want to have too many threads running,
> > > > technically
> > > > > > you
> > > > > > > can only have one run per core and anything after that is going to
> > > be
> > > > time
> > > > > > > slicing.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > HTML
> > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > earlier.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > loop
> > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > Within
> > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > and
> > > > > > > when that happens I update the less important items.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Very basic setup that only uses one additional thread that updates
> > > the
> > > > > > DRO's
> > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > updated
> > > > > > > every ½ a second.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will re-upload my source so you can see how it works.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > >
> > > > > > > I can see how I could use parallel threads to make the display
> > > updates
> > > > > > more
> > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > concurrency
> > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > just
> > > > > > > checked and my update loop is running only about 5X/second right
> > > now,
> > > > > > though
> > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > really
> > > > > > > need to be sped up.
> > > > > > >
> > > > > > > How would you do it?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > a
> > > > > > > > reference to a control you are using(best bet is the main window)
> > > to
> > > > > > your
> > > > > > > > middle layer.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > control
> > > > > > > as
> > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > >
> > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > and
> > > > > > > > high-level. All communications passes through that layer, and it
> > > > also
> > > > > > > allows
> > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > test
> > > > > > > the
> > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Who you calling Gary? ;)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Gary,
> > > > > > > > >
> > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > assume
> > > > > > > > that
> > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > something
> > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > interact
> > > > > > > with
> > > > > > > > > the
> > > > > > > > > > kflop will be much smoother.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > can
> > > > > > > either
> > > > > > > > > use
> > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > using
> > > > > > > > > .net4.0
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Parallel tasks are best because the will automagically load
> > > your
> > > > cpu
> > > > > > > > usage
> > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Background workers are pretty easy to use and have a
> > > > comprehensive
> > > > > > use
> > > > > > > > > > model.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > easy
> > > > > > to
> > > > > > > > use
> > > > > > > > > to
> > > > > > > > > > and easy to read.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > your
> > > > > > > control
> > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > pseudo-example
> > > > > > > > > > where I am using a common method that takes an Action as a
> > > > parameter
> > > > > > > and
> > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > is
> > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > thread
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > else
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > invocation required
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > you
> > > > > > can
> > > > > > > > use
> > > > > > > > > > the above method like so::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > //Put your control updating code here.
> > > > > > > > > >
> > > > > > > > > > //Example:
> > > > > > > > > >
> > > > > > > > > > lblXaxisDest.Text =
> > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > >
> > > > > > > > > > }));
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > most
> > > > > > > parts,
> > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > For
> > > > > > > > > example,
> > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > execute a
> > > > > > > line
> > > > > > > > > of
> > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > running,
> > > > > > > the
> > > > > > > > > DROs
> > > > > > > > > > update in significant increments, rather than the relatively
> > > > smooth
> > > > > > > > > updates
> > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > 100mSec,
> > > > > > > so
> > > > > > > > I
> > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > my
> > > > > > > code,
> > > > > > > > so
> > > > > > > > > > none of this concerns me at all at this early stage of the
> > > game.
> > > > > > > > > >
> > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > threads,
> > > > > > > > I've
> > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > question
> > > > > > > > > under
> > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > KMotionCNC,
> > > > > > > > they
> > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > But,
> > > > > > run
> > > > > > > > them
> > > > > > > > > > under my app, using the few lines of code posted last night,
> > > and
> > > > the
> > > > > > > > > threads
> > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > lunch.
> > > > > > > > KMotion
> > > > > > > > > > confirms the threads remain running long after they should
> > > have
> > > > > > > > > terminated,
> > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > here's
> > > > the
> > > > > > > > > bizarre
> > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > open
> > > > > > the
> > > > > > > > app
> > > > > > > > > -
> > > > > > > > > > the thread immediately picks up and runs to completion
> > > > correctly! If
> > > > > > I
> > > > > > > > > just
> > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > work
> > > > > > > > > perfectly
> > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > message
> > > > > > > to
> > > > > > > > > the
> > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > MsgBox
> > > > > > > > does
> > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > thread
> > > > > > was
> > > > > > > > > > launched from MY app!
> > > > > > > > > >
> > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > my
> > > > DSP
> > > > > > > > > programs
> > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > when
> > > > > > it
> > > > > > > > did
> > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > that's
> > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > here...
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Group: DynoMotion Message: 3532 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Hello Tom,

 

Do you think my theory about the multiple Token Locks could be causing the issue?

 

 

I certainly want to get MainStatus working too, and only recommended removing it’s use for troubleshooting purposes.

 

BTW, can’t wait for the error callbacks!!!!

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
Sent: Friday, January 27, 2012 10:49 AM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Hi Ray,

 

I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.  It should be possible to get that MainStatus function working reliably.  I will try to find time to look at it soon.  I'm currently trying to get the Error Callbacks working.

 

Regards

TK

 

 

From: himykabibble <jagboy@...>
To: DynoMotion@yahoogroups.com
Sent: Friday, January 27, 2012 8:54 AM
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!

I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.

One new problem that has crept in:

I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.

Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.

Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > > Once you pull all those locks out ;).....
> > >
> > > Can you try something else for the sake of argument?
> > >
> > > Remove the use of the MainStatus and just get the axis values from the
> > > interpreter and get your IO status from your KM_IO objects.
> > >
> > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > >
> > > Are you game?
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > >
> > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > >
> > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Guys,
> > > > >  
> > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > >  
> > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > >  
> > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > >  
> > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > >  
> > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > >  
> > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > >  
> > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > >  
> > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > >
> > > > > Anyway, just some thoughts..
> > > > > Thanks
> > > > > TK
> > > > >  
> > > > >  
> > > > >
> > > > > ________________________________
> > > > > From: bradodarb <bradodarb@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > > Yes, lock every call.
> > > > >
> > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > >
> > > > > looking forward to hearing back your results.
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > >
> > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > with the only goal of finding your problem.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > access the controller object.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > to be placed in a lock.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example2::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Do stuff with your controller here
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > But perhaps a simple example:
> > > > > > >
> > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > >
> > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > >
> > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > >
> > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Hello Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I would probably need to see some code to be much help.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > now,
> > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > thread? Or is there a better way?
> > > > > > > >
> > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > to
> > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > but
> > > > > > > > doesn't exit.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > but,
> > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > still
> > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > rendering
> > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > can
> > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > update
> > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > controls,
> > > > > > > > by
> > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > ticks.
> > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > getting
> > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > since
> > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > technically
> > > > > > > > > > you
> > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > be
> > > > > > > > time
> > > > > > > > > > > slicing.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > HTML
> > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > earlier.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > loop
> > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > Within
> > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > and
> > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > the
> > > > > > > > > > DRO's
> > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > updated
> > > > > > > > > > > every ½ a second.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > >
> > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > updates
> > > > > > > > > > more
> > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > concurrency
> > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > just
> > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > now,
> > > > > > > > > > though
> > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > really
> > > > > > > > > > > need to be sped up.
> > > > > > > > > > >
> > > > > > > > > > > How would you do it?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > a
> > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > to
> > > > > > > > > > your
> > > > > > > > > > > > middle layer.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > control
> > > > > > > > > > > as
> > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > and
> > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > also
> > > > > > > > > > > allows
> > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > test
> > > > > > > > > > > the
> > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Gary,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > assume
> > > > > > > > > > > > that
> > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > something
> > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > interact
> > > > > > > > > > > with
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > can
> > > > > > > > > > > either
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > using
> > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > your
> > > > > > > > cpu
> > > > > > > > > > > > usage
> > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > &g

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3533 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Ray,

 

OK, I will look into taking the lock token code out of the c++ call.  This will mean that you will need lock and release methods surrounding your UpdateMainStatus once you move back to using those.

 

 

Thanks for your help!

 

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Friday, January 27, 2012 9:55 AM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!

I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.

One new problem that has crept in:

I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.

Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.

Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > > Once you pull all those locks out ;).....
> > >
> > > Can you try something else for the sake of argument?
> > >
> > > Remove the use of the MainStatus and just get the axis values from the
> > > interpreter and get your IO status from your KM_IO objects.
> > >
> > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > >
> > > Are you game?
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > >
> > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > >
> > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Guys,
> > > > >  
> > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > >  
> > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > >  
> > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > >  
> > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > >  
> > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > >  
> > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > >  
> > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > >  
> > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > >
> > > > > Anyway, just some thoughts..
> > > > > Thanks
> > > > > TK
> > > > >  
> > > > >  
> > > > >
> > > > > ________________________________
> > > > > From: bradodarb <bradodarb@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > > Yes, lock every call.
> > > > >
> > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > >
> > > > > looking forward to hearing back your results.
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > >
> > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > with the only goal of finding your problem.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > access the controller object.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > to be placed in a lock.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Example2::
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > lock(_Controller)
> > > > > > >
> > > > > > > {
> > > > > > >
> > > > > > > //Do stuff with your controller here
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > But perhaps a simple example:
> > > > > > >
> > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > >
> > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > >
> > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > >
> > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Hello Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I would probably need to see some code to be much help.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > now,
> > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > thread? Or is there a better way?
> > > > > > > >
> > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > to
> > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > but
> > > > > > > > doesn't exit.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > but,
> > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > still
> > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > rendering
> > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > can
> > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > update
> > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > controls,
> > > > > > > > by
> > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > ticks.
> > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > getting
> > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > since
> > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > technically
> > > > > > > > > > you
> > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > be
> > > > > > > > time
> > > > > > > > > > > slicing.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > HTML
> > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > earlier.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > loop
> > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > Within
> > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > and
> > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > the
> > > > > > > > > > DRO's
> > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > updated
> > > > > > > > > > > every ½ a second.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > >
> > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > updates
> > > > > > > > > > more
> > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > concurrency
> > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > just
> > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > now,
> > > > > > > > > > though
> > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > really
> > > > > > > > > > > need to be sped up.
> > > > > > > > > > >
> > > > > > > > > > > How would you do it?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > a
> > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > to
> > > > > > > > > > your
> > > > > > > > > > > > middle layer.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > control
> > > > > > > > > > > as
> > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > and
> > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > also
> > > > > > > > > > > allows
> > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > test
> > > > > > > > > > > the
> > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Gary,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > assume
> > > > > > > > > > > > that
> > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > something
> > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > interact
> > > > > > > > > > > with
> > > > > > > > > > > > > the
> > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > can
> > > > > > > > > > > either
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > using
> > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > your
> > > > > > > > cpu
> > > > > > > > > > > > usage
> > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > comprehensive
> > > > > > > > > > use
> > > > > > > > > > > > > > model.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > easy
> > > > > > > > > > to
> > > > > > > > > > > > use
> > > > > > > > > > > > > to
> > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > your
> > > > > > > > > > > control
> > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > parameter
> > > > > > > > > > > and
> > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > {
> > > > > > > > > > &g

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3534 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

I am not suggesting to abandon it permanently, just to bypass it for now to see if calling the update is causing the lock up.

 

 

When you call UpdateMainStatus(), and it gets to the c++ side it is acquiring a token lock in pretty much the exact same way as KMotionCNC is doing(I used the code from KMotionCNC to perform the update status and just stripped out KMotionCNC’s GUI related calls).

 

 

 

My theory is we are locking in two places and entering a deadlock.

 

 

 

The other thing I wanted you to try was see if the locking occurs or occurs as often when only your app is accessing the kflop(no KMotion.exe or KMotionCNC  running)

 

Thanks Ray,

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Friday, January 27, 2012 9:15 AM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> >
> > Ray,
> >
> >
> > Once you pull all those locks out ;).....
> >
> > Can you try something else for the sake of argument?
> >
> > Remove the use of the MainStatus and just get the axis values from the
> > interpreter and get your IO status from your KM_IO objects.
> >
> > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> >
> > Are you game?
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Tom,
> > >
> > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > >
> > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > >
> > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Guys,
> > > >  
> > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > >  
> > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > >  
> > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > >  
> > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > >  
> > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > >  
> > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > >  
> > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > >  
> > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > >
> > > > Anyway, just some thoughts..
> > > > Thanks
> > > > TK
> > > >  
> > > >  
> > > >
> > > > ________________________________
> > > > From: bradodarb <bradodarb@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > >
> > > > Hello Ray,
> > > >
> > > > Yes, lock every call.
> > > >
> > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > >
> > > > looking forward to hearing back your results.
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > >
> > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > Ray,
> > > > > >
> > > > > >
> > > > > >
> > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > with the only goal of finding your problem.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > access the controller object.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Example::
> > > > > >
> > > > > >
> > > > > >
> > > > > > lock(_Controller)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > >
> > > > > >
> > > > > >
> > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > to be placed in a lock.
> > > > > >
> > > > > >
> > > > > >
> > > > > > Example2::
> > > > > >
> > > > > >
> > > > > >
> > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > lock(_Controller)
> > > > > >
> > > > > > {
> > > > > >
> > > > > > //Do stuff with your controller here
> > > > > >
> > > > > > }
> > > > > >
> > > > > > }
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > But perhaps a simple example:
> > > > > >
> > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > >
> > > > > > Some of the Button Click handlers also need to access things in
> > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > method in my dotNet "gasket" that handles all this.
> > > > > >
> > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > >
> > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > Hello Ray,
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I would probably need to see some code to be much help.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > now,
> > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > thread? Or is there a better way?
> > > > > > >
> > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > to
> > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > but
> > > > > > > doesn't exit.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > but,
> > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > still
> > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > called. Not sure I understand why that's happening.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > rendering
> > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > can
> > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > update
> > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > controls,
> > > > > > > by
> > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > ticks.
> > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > getting
> > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > since
> > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > technically
> > > > > > > > > you
> > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > be
> > > > > > > time
> > > > > > > > > > slicing.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > HTML
> > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > earlier.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > loop
> > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > Within
> > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > and
> > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > the
> > > > > > > > > DRO's
> > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > updated
> > > > > > > > > > every ½ a second.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > >
> > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > updates
> > > > > > > > > more
> > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > concurrency
> > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > just
> > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > now,
> > > > > > > > > though
> > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > really
> > > > > > > > > > need to be sped up.
> > > > > > > > > >
> > > > > > > > > > How would you do it?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > a
> > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > to
> > > > > > > > > your
> > > > > > > > > > > middle layer.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > control
> > > > > > > > > > as
> > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > >
> > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > and
> > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > also
> > > > > > > > > > allows
> > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > test
> > > > > > > > > > the
> > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Gary,
> > > > > > > > > > > >
> > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > assume
> > > > > > > > > > > that
> > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > something
> > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > interact
> > > > > > > > > > with
> > > > > > > > > > > > the
> > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > can
> > > > > > > > > > either
> > > > > > > > > > > > use
> > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > using
> > > > > > > > > > > > .net4.0
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > your
> > > > > > > cpu
> > > > > > > > > > > usage
> > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > comprehensive
> > > > > > > > > use
> > > > > > > > > > > > > model.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > easy
> > > > > > > > > to
> > > > > > > > > > > use
> > > > > > > > > > > > to
> > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > your
> > > > > > > > > > control
> > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > pseudo-example
> > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > parameter
> > > > > > > > > > and
> > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > is
> > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > thread
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > else
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > invocation required
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > > }
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > you
> > > > > > > > > can
> > > > > > > > > > > use
> > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > >
> > > > > > > > > > > > > {
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > >
> > > > > > > > > > > > > //Example:
> > > > > > > > &

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3535 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

The IO is also using underlying direct script calls requiring the round trip, so yes .

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Friday, January 27, 2012 10:56 AM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Tom,

Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.  It should be possible to get that MainStatus function working reliably.  I will try to find time to look at it soon.  I'm currently trying to get the Error Callbacks working.
>  
> Regards
> TK
>  
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Friday, January 27, 2012 8:54 AM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> Brad,
>
> OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
>
> I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
>
> One new problem that has crept in:
>
> I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
>
> Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
>
> Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > > Once you pull all those locks out ;).....
> > > >
> > > > Can you try something else for the sake of argument?
> > > >
> > > > Remove the use of the MainStatus and just get the axis values from the
> > > > interpreter and get your IO status from your KM_IO objects.
> > > >
> > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > >
> > > > Are you game?
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Tom,
> > > > >
> > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > >
> > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > >
> > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Guys,
> > > > > >  
> > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > >  
> > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > >  
> > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > >  
> > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > >  
> > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.  If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out.  And in some cases this might even cause a dead lock.
> > > > > >  
> > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.  So the Token prevents this as well.
> > > > > >  
> > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.  Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work.  But I can't see where anything would block while just trying to render the screen.  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > >  
> > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > >
> > > > > > Anyway, just some thoughts..
> > > > > > Thanks
> > > > > > TK
> > > > > >  
> > > > > >  
> > > > > >
> > > > > > ________________________________
> > > > > > From: bradodarb <bradodarb@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > >
> > > > > > Hello Ray,
> > > > > >
> > > > > > Yes, lock every call.
> > > > > >
> > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > >
> > > > > > looking forward to hearing back your results.
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > >
> > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > with the only goal of finding your problem.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > access the controller object.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > to be placed in a lock.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example2::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > //Do stuff with your controller here
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > But perhaps a simple example:
> > > > > > > >
> > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > >
> > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > >
> > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > >
> > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Hello Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > now,
> > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > thread? Or is there a better way?
> > > > > > > > >
> > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > to
> > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > but
> > > > > > > > > doesn't exit.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > but,
> > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > still
> > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > rendering
> > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > can
> > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > update
> > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > controls,
> > > > > > > > > by
> > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > ticks.
> > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > getting
> > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > since
> > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > technically
> > > > > > > > > > > you
> > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > be
> > > > > > > > > time
> > > > > > > > > > > > slicing.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > HTML
> > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > earlier.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > loop
> > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > Within
> > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > and
> > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > the
> > > > > > > > > > > DRO's
> > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > > updated
> > > > > > > > > > > > every ½ a second.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > updates
> > > > > > > > > > > more
> > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > concurrency
> > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > just
> > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > now,
> > > > > > > > > > > though
> > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > really
> > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > >
> > > > > > > > > > > > How would you do it?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > a
> > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > to
> > > > > > > > > > > your
> > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > control
> > > > > > > > > > > > as
> > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > and
> > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > also
> > > > > > > > > > > > allows
> > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > test
> > > > > > > > > > > > the
> > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > assume
> > > > > > > > > > > > > that
> > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > something
> > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > interact
> > > > > > > > > > > > with
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > can
> > > > > > > > > > > > either
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > using
> > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > your
> > > > > > > > > cpu
> > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > based on how many cores are avai

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3536 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Tom,

Oops…  Looks like I only marshaled the return value on WriteLineReadLine.

 

Ray,

 

In .net, create the variable you will pass to the ReadLineTimeout like so::

 

var s = new string(' ', 255);

 

-Brad Murry

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
Sent: Saturday, January 28, 2012 8:34 PM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Hi Ray,

 

I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.

 

Regards

TK

 

From: himykabibble <jagboy@...>
To: DynoMotion@yahoogroups.com
Sent: Saturday, January 28, 2012 6:39 PM
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
>
> main()
> {
> KM_Controller KM = new KM_Controller();
> Thread.Sleep(1000);
> GatherHex(0, 8);
> }
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad/Tom,
> >
> > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> >
> > Here's the code on my side:
> >
> > public String[] GatherHex(int offset, int words)
> > {
> > String[] ret = new String[words];
> > int lines = (words + 7) / 8;
> > String[] s = new String[lines];
> >
> > WaitToken();
> > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > for (int i = 0; i < lines; i++)
> > KMController.ReadLineTimout(ref s[i], 500);
> > ReleaseToken();
> > int thisword = 0;
> > foreach (String t in s)
> > {
> > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > {
> > ret[thisword] = u;
> > if (++thisword == words)
> > break;
> > }
> > }
> > return ret;
> > }
> >
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > >
> > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > >
> > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > >
> > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > >
> > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > OK, not using that.
> > > >
> > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > >  
> > > > > That is something relatively new and can only be set via C code as shown below:
> > > > >  
> > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > >  
> > > > > It is described in the latter half of this document
> > > > >  
> > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > >  
> > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > >  
> > > > > TK
> > > > >  
> > > > >  
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > > Tom,
> > > > >
> > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > >  
> > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > >  
> > > > > > Regards
> > > > > > TK
> > > > > >
> > > > > >
> > > > > > ________________________________
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > >
> > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > >  
> > > > > > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > >  
> > > > > > > TK
> > > > > > >
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > > Tom,
> > > > > > >
> > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > > ÃÆ'‚ 
> > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Regards
> > > > > > > > TK
> > > > > > > > ÃÆ'‚ 
> > > > > > > >
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > >
> > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > >
> > > > > > > > One new problem that has crept in:
> > > > > > > >
> > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > >
> > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > >
> > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > >
> > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > >
> > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > >
> > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > >
> > > > > > > > > > > Are you game?
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > >
> > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > TK
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > >
> > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > >
> > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > >

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3537 From: Tom Kerekes Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,
 
So sorry when you post from your hotmail account Yahoo flags them as spam for some reason.
 
I just noticed and "unspammed" 9 of your emails.
 
TK

Group: DynoMotion Message: 3538 From: Brad Murry Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Thanks Tom,

 

That’s odd, must have happened recently as I post back to the group from Hotmail(via Outlook) 99% of the time.  I think I have noticed posts not showing up for about a week.

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
Sent: Saturday, January 28, 2012 9:26 PM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

 

So sorry when you post from your hotmail account Yahoo flags them as spam for some reason.

 

I just noticed and "unspammed" 9 of your emails.

 

TK

 

From: Brad Murry <bradodarb@...>
To: DynoMotion@yahoogroups.com
Sent: Saturday, January 28, 2012 8:08 PM
Subject: RE: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Tom,

Oops…  Looks like I only marshaled the return value on WriteLineReadLine.

 

Ray,

 

In .net, create the variable you will pass to the ReadLineTimeout like so::

 

var s = new string(' ', 255);

 

-Brad Murry

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
Sent: Saturday, January 28, 2012 8:34 PM
To: DynoMotion@yahoogroups.com
Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Hi Ray,

 

I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.

 

Regards

TK

 

From: himykabibble <jagboy@...>
To: DynoMotion@yahoogroups.com
Sent: Saturday, January 28, 2012 6:39 PM
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
>
> main()
> {
> KM_Controller KM = new KM_Controller();
> Thread.Sleep(1000);
> GatherHex(0, 8);
> }
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad/Tom,
> >
> > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> >
> > Here's the code on my side:
> >
> > public String[] GatherHex(int offset, int words)
> > {
> > String[] ret = new String[words];
> > int lines = (words + 7) / 8;
> > String[] s = new String[lines];
> >
> > WaitToken();
> > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > for (int i = 0; i < lines; i++)
> > KMController.ReadLineTimout(ref s[i], 500);
> > ReleaseToken();
> > int thisword = 0;
> > foreach (String t in s)
> > {
> > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > {
> > ret[thisword] = u;
> > if (++thisword == words)
> > break;
> > }
> > }
> > return ret;
> > }
> >
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > >
> > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > >
> > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > >
> > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > >
> > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > OK, not using that.
> > > >
> > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > >  
> > > > > That is something relatively new and can only be set via C code as shown below:
> > > > >  
> > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > >  
> > > > > It is described in the latter half of this document
> > > > >  
> > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > >  
> > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > >  
> > > > > TK
> > > > >  
> > > > >  
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > > Tom,
> > > > >
> > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > >  
> > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > >  
> > > > > > Regards
> > > > > > TK
> > > > > >
> > > > > >
> > > > > > ________________________________
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > >
> > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > >  
> > > > > > > Yes.  Everything.  There is basically only two ways to get info from KFLOP.  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > >  
> > > > > > > TK
> > > > > > >
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > > Tom,
> > > > > > >
> > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > > ÃÆ'‚ 
> > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Regards
> > > > > > > > TK
> > > > > > > > ÃÆ'‚ 
> > > > > > > >
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > >
> > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > >
> > > > > > > > One new problem that has crept in:
> > > > > > > >
> > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > >
> > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > >
> > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > >
> > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > >
> > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > >
> > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > >
> > > > > > > > > > > Are you game?
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > >
> > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > TK
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > >
> > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > >
> > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'‚¦.
> > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > >

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3539 From: Tom Kerekes Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Brad,
 
I don't know or have control over it.  I had to manually approve his one also.  You would think it would learn.
 
Regards
TK

Group: DynoMotion Message: 3542 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

"#2 A separate GUI update thread is advantageous here because updating the data is taking <100ms at some times. If a timer is being used with say a 100ms interval and the task is taking 200ms then the GUI will be locked as the next timer ‘tick’ event will have been fired before the last was completed." - I actually dealt with this potential by stopping the timer at the top of the event handler, and starting it at the bottom.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Tom,
>
>
>
> #1Good, but I suggested the lock to make sure we weren’t trying to grab a token from multiple threads. I think I understand that the token will be atomic and only be given to the calling thread but my thoughts were a lock will cause the next calling thread to wait until the other thread is done.
>
>
>
> #2 A separate GUI update thread is advantageous here because updating the data is taking <100ms at some times. If a timer is being used with say a 100ms interval and the task is taking 200ms then the GUI will be locked as the next timer ‘tick’ event will have been fired before the last was completed.
>
>
>
> By having the updating on a separate thread, the update process can take however long as is needed and update every cycle.
>
>
>
> #3 The Task Parallel library in .net 4.0 will distribute amongst cores when possible.
>
>
>
>
>
> Not saying the above is set in stone gospel(except 3), but is where I was coming from.
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
> Sent: Thursday, January 26, 2012 11:10 PM
> To: DynoMotion@yahoogroups.com
> Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Hi Guys,
>
>
>
> I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail. And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
>
>
>
> Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
>
>
>
> #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already. WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic. The one exception is a WriteLine which sends a command that will take N ReadLines to get the response. In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up. So the WaitToken ReleaseToken can be used to avoid this problem.
>
>
>
> The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
>
>
>
> The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time. If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out. And in some cases this might even cause a dead lock.
>
>
>
> There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works. If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread. So the Token prevents this as well.
>
>
>
> #2 I can't see how multiple threads would help the Screen Update rate in any way. Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work. But I can't see where anything would block while just trying to render the screen. The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something. But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
>
>
>
> #3 I don't think multiple threads allows you to make use of multiple CPU cores. In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps). When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
>
>
> Anyway, just some thoughts..
>
> Thanks
>
> TK
>
>
>
>
>
> From: bradodarb <bradodarb@...>
> To: DynoMotion@yahoogroups.com
> Sent: Thursday, January 26, 2012 8:46 PM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Hello Ray,
>
> Yes, lock every call.
>
> MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
>
> looking forward to hearing back your results.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> >
> > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> >
> > Regards,
> > Ray L.
> >
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Brad Murry <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > >
> > >
> > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > with the only goal of finding your problem.
> > >
> > >
> > >
> > >
> > >
> > > Before that , you could try to surround any calls to the KM_Controller
> > > instance with a lock clause. This will allow only one thread at a time to
> > > access the controller object.
> > >
> > >
> > >
> > > Example::
> > >
> > >
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > var status = _Controller.WriteLineReadLine("Version");
> > >
> > >
> > >
> > > var status2 = _Controller.WriteLineReadLine("Version");
> > >
> > > }
> > >
> > >
> > >
> > > Basically, any function you are using the KM_Controller instance in may need
> > > to be placed in a lock.
> > >
> > >
> > >
> > > Example2::
> > >
> > >
> > >
> > > Public void MyUpdatingOrCommandingFunction(args….)
> > >
> > > {
> > >
> > > lock(_Controller)
> > >
> > > {
> > >
> > > //Do stuff with your controller here
> > >
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > > Try this and let me know if it helps. It is making sense to me that the
> > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > I never ran into it on MM as it never accesses the GUI thread.
> > >
> > >
> > >
> > > -Brad Murry
> > >
> > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ] On
> > > Behalf Of himykabibble
> > > Sent: Thursday, January 26, 2012 9:14 PM
> > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >
> > >
> > >
> > > Brad,
> > >
> > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > But perhaps a simple example:
> > >
> > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > current tool, spindle RPM, and a number of other things. Those are currently
> > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > >
> > > Some of the Button Click handlers also need to access things in
> > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > method in my dotNet "gasket" that handles all this.
> > >
> > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > be better to have only one thread talking the KM_Controller? If so, should I
> > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > vice-versa. Or perhaps there's another/better option?
> > >
> > > I looked through your HTML app code, but you don't seem to be dealing with
> > > that problem yet, since it appears to me only the DROs are actually
> > > functional, and their operation is straight-forward (though I note you are
> > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ,
> > > Brad Murry <bradodarb@> wrote:
> > > >
> > > > Hello Ray,
> > > >
> > > >
> > > >
> > > > I would probably need to see some code to be much help.
> > > >
> > > >
> > > >
> > > > Brad Murry
> > > >
> > > >
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ]
> > > On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > clear on the right way to handle communications with dotNet. My UI update
> > > > thread needs to access various dotNet data to create the updates. Right
> > > now,
> > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > contains the UI status, then tossing that over to the UI thread to update
> > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > thread? Or is there a better way?
> > > >
> > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > to
> > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > but
> > > > doesn't exit.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > but,
> > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > display update performance. It also, not surprisingly, introduced a couple
> > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > still
> > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > called. Not sure I understand why that's happening.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > > >
> > > > > > The only thing I will add at this point is try it and you will see.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > rendering
> > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > can
> > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > -Brad
> > > > > >
> > > > > >
> > > > > >
> > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > > Behalf Of himykabibble
> > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > update
> > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > controls. I already update the DROs more often than the other
> > > controls,
> > > > by
> > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > ticks.
> > > > > > How will another thread improve performance, if the bottleneck is
> > > > getting
> > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > since
> > > > > > I have to go through an invoke to modify each control?
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > >
> > > > > > > First off, you never want to have too many threads running,
> > > > technically
> > > > > > you
> > > > > > > can only have one run per core and anything after that is going to
> > > be
> > > > time
> > > > > > > slicing.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > HTML
> > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > earlier.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > loop
> > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > Within
> > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > and
> > > > > > > when that happens I update the less important items.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Very basic setup that only uses one additional thread that updates
> > > the
> > > > > > DRO's
> > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > updated
> > > > > > > every ½ a second.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will re-upload my source so you can see how it works.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad Murry
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > >
> > > > > > > I can see how I could use parallel threads to make the display
> > > updates
> > > > > > more
> > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > concurrency
> > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > just
> > > > > > > checked and my update loop is running only about 5X/second right
> > > now,
> > > > > > though
> > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > really
> > > > > > > need to be sped up.
> > > > > > >
> > > > > > > How would you do it?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > a
> > > > > > > > reference to a control you are using(best bet is the main window)
> > > to
> > > > > > your
> > > > > > > > middle layer.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > control
> > > > > > > as
> > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > >
> > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > and
> > > > > > > > high-level. All communications passes through that layer, and it
> > > > also
> > > > > > > allows
> > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > test
> > > > > > > the
> > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Who you calling Gary? ;)
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Gary,
> > > > > > > > >
> > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > assume
> > > > > > > > that
> > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > something
> > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Ray,
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > interact
> > > > > > > with
> > > > > > > > > the
> > > > > > > > > > kflop will be much smoother.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > can
> > > > > > > either
> > > > > > > > > use
> > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > using
> > > > > > > > > .net4.0
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Parallel tasks are best because the will automagically load
> > > your
> > > > cpu
> > > > > > > > usage
> > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Background workers are pretty easy to use and have a
> > > > comprehensive
> > > > > > use
> > > > > > > > > > model.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > easy
> > > > > > to
> > > > > > > > use
> > > > > > > > > to
> > > > > > > > > > and easy to read.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > your
> > > > > > > control
> > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > pseudo-example
> > > > > > > > > > where I am using a common method that takes an Action as a
> > > > parameter
> > > > > > > and
> > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > is
> > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > thread
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > else
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > invocation required
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > you
> > > > > > can
> > > > > > > > use
> > > > > > > > > > the above method like so::
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > >
> > > > > > > > > > {
> > > > > > > > > >
> > > > > > > > > > //Put your control updating code here.
> > > > > > > > > >
> > > > > > > > > > //Example:
> > > > > > > > > >
> > > > > > > > > > lblXaxisDest.Text =
> > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > >
> > > > > > > > > > }));
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > most
> > > > > > > parts,
> > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > For
> > > > > > > > > example,
> > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > execute a
> > > > > > > line
> > > > > > > > > of
> > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > running,
> > > > > > > the
> > > > > > > > > DROs
> > > > > > > > > > update in significant increments, rather than the relatively
> > > > smooth
> > > > > > > > > updates
> > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > 100mSec,
> > > > > > > so
> > > > > > > > I
> > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > my
> > > > > > > code,
> > > > > > > > so
> > > > > > > > > > none of this concerns me at all at this early stage of the
> > > game.
> > > > > > > > > >
> > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > threads,
> > > > > > > > I've
> > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > question
> > > > > > > > > under
> > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > KMotionCNC,
> > > > > > > > they
> > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > But,
> > > > > > run
> > > > > > > > them
> > > > > > > > > > under my app, using the few lines of code posted last night,
> > > and
> > > > the
> > > > > > > > > threads
> > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > lunch.
> > > > > > > > KMotion
> > > > > > > > > > confirms the threads remain running long after they should
> > > have
> > > > > > > > > terminated,
> > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > here's
> > > > the
> > > > > > > > > bizarre
> > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > open
> > > > > > the
> > > > > > > > app
> > > > > > > > > -
> > > > > > > > > > the thread immediately picks up and runs to completion
> > > > correctly! If
> > > > > > I
> > > > > > > > > just
> > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > work
> > > > > > > > > perfectly
> > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > message
> > > > > > > to
> > > > > > > > > the
> > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > MsgBox
> > > > > > > > does
> > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > thread
> > > > > > was
> > > > > > > > > > launched from MY app!
> > > > > > > > > >
> > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > my
> > > > DSP
> > > > > > > > > programs
> > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > when
> > > > > > it
> > > > > > > > did
> > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > that's
> > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > here...
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3543 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom,

Did not know that was required.... I'll give it a try.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
>  
> Regards
> TK
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Saturday, January 28, 2012 6:39 PM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> >
> > main()
> > {
> > KM_Controller KM = new KM_Controller();
> > Thread.Sleep(1000);
> > GatherHex(0, 8);
> > }
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad/Tom,
> > >
> > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > >
> > > Here's the code on my side:
> > >
> > > public String[] GatherHex(int offset, int words)
> > > {
> > > String[] ret = new String[words];
> > > int lines = (words + 7) / 8;
> > > String[] s = new String[lines];
> > >
> > > WaitToken();
> > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > for (int i = 0; i < lines; i++)
> > > KMController.ReadLineTimout(ref s[i], 500);
> > > ReleaseToken();
> > > int thisword = 0;
> > > foreach (String t in s)
> > > {
> > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > {
> > > ret[thisword] = u;
> > > if (++thisword == words)
> > > break;
> > > }
> > > }
> > > return ret;
> > > }
> > >
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > >
> > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > >
> > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > >
> > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > >
> > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Tom,
> > > > >
> > > > > OK, not using that.
> > > > >
> > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > >  
> > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > >  
> > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > >  
> > > > > > It is described in the latter half of this document
> > > > > >  
> > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > >  
> > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > >  
> > > > > > TK
> > > > > >  
> > > > > >  
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > > Tom,
> > > > > >
> > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > >  
> > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > >  
> > > > > > > Regards
> > > > > > > TK
> > > > > > >
> > > > > > >
> > > > > > > ________________________________
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > >
> > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Yes.ÃÆ'‚  Everything.ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > ÃÆ'‚ 
> > > > > > > > TK
> > > > > > > >
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > > ÃÆ'‚ 
> > > > > > > > Tom,
> > > > > > > >
> > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Ray,
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > Regards
> > > > > > > > > TK
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > >
> > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > >
> > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > >
> > > > > > > > > One new problem that has crept in:
> > > > > > > > >
> > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > >
> > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > >
> > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Ray,
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > >
> > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > >
> > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > >
> > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > >
> > > > > > > > > > > > Are you game?
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Tom,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > >
> > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > > > > > > most
> > > > > > > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > > > > > > execute a
> > > > > > > > > > > > > > > > > > > > line
> > > > > > > > > > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > > > > > > > > > running,
> > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > > > > > > > > > smooth
> > > > > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > > > > > > > > > 100mSec,
> > > > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > > > I
> > > > > > > > > > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > > > > > > > > > my
> > > > > > > > > > > > > > > > > > > > code,
> > > > > > > > > > > > > > > > > > > > > so
> > > > > > > > > > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > > > > > > > > > game.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > > > > > > > > > threads,
> > > > > > > > > > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > > > > > > > > > question
> > > > > > > > > > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > > > > > > > > > they
> > > > > > > > > > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > > > > > > > > > But,
> > > > > > > > > > > > > > > > > > > run
> > > > > > > > > > > > > > > > > > > > > them
> > > > > > > > > > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > <br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3544 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Before removing the MainStatus call, yes, definitely. Since then I'm not sure. I've seen a few "hangs", but was not in a position to see where they were coming from. Could still be bugs in my code. It is certainly much easier to get things into a whacked state with multiple apps running.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Ray,
>
>
>
> Do you have the locking problem when no other applications that use the Kflop are running?(KMotion.exe, KMotionCNC.exe)?
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
> Sent: Friday, January 27, 2012 12:00 AM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Posted as MyKFlopCPrograms.zip...
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> >
> > Brad
> >
> > Coming right up....
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "bradodarb" <bradodarb@> wrote:
> > >
> > > Ray,
> > >
> > > For clarity, please post your spindle.c files the bug tester is looking for so I can debug it.
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "bradodarb" <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > > Once you pull all those locks out ;).....
> > > >
> > > > Can you try something else for the sake of argument?
> > > >
> > > > Remove the use of the MainStatus and just get the axis values from the
> > > > interpreter and get your IO status from your KM_IO objects.
> > > >
> > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > >
> > > > Are you game?
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Tom,
> > > > >
> > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > >
> > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > >
> > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Guys,
> > > > > > Â
> > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail. And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > Â
> > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > Â
> > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already. WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic. The one exception is a WriteLine which sends a command that will take N ReadLines to get the response. In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up. So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > Â
> > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > Â
> > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time. If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out. And in some cases this might even cause a dead lock.
> > > > > > Â
> > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works. If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread. So the Token prevents this as well.
> > > > > > Â
> > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way. Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work. But I can't see where anything would block while just trying to render the screen. The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something. But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > > > > > Â
> > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores. In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps). When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > >
> > > > > > Anyway, just some thoughts..
> > > > > > Thanks
> > > > > > TK
> > > > > > Â
> > > > > > Â
> > > > > >
> > > > > > ________________________________
> > > > > > From: bradodarb <bradodarb@>
> > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > > Â
> > > > > >
> > > > > > Hello Ray,
> > > > > >
> > > > > > Yes, lock every call.
> > > > > >
> > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > >
> > > > > > looking forward to hearing back your results.
> > > > > >
> > > > > > -Brad Murry
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > >
> > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > > Ray,
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > with the only goal of finding your problem.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > access the controller object.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > to be placed in a lock.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Example2::
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > lock(_Controller)
> > > > > > > >
> > > > > > > > {
> > > > > > > >
> > > > > > > > //Do stuff with your controller here
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ] On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > But perhaps a simple example:
> > > > > > > >
> > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > >
> > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > >
> > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > >
> > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Hello Ray,
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad Murry
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > now,
> > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > thread? Or is there a better way?
> > > > > > > > >
> > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > to
> > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > but
> > > > > > > > > doesn't exit.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > but,
> > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > still
> > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > rendering
> > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > can
> > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > update
> > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > controls,
> > > > > > > > > by
> > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > ticks.
> > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > getting
> > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > since
> > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > technically
> > > > > > > > > > > you
> > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > be
> > > > > > > > > time
> > > > > > > > > > > > slicing.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > HTML
> > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > earlier.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > loop
> > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > Within
> > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > and
> > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > the
> > > > > > > > > > > DRO's
> > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > > > > > updated
> > > > > > > > > > > > every ½ a second.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > On
> > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > >
> > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > updates
> > > > > > > > > > > more
> > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > concurrency
> > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > just
> > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > now,
> > > > > > > > > > > though
> > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > really
> > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > >
> > > > > > > > > > > > How would you do it?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > a
> > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > to
> > > > > > > > > > > your
> > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > control
> > > > > > > > > > > > as
> > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > On
> > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > >
> > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > and
> > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > also
> > > > > > > > > > > > allows
> > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > test
> > > > > > > > > > > > the
> > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > On
> > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > assume
> > > > > > > > > > > > > that
> > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > something
> > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > interact
> > > > > > > > > > > > with
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > can
> > > > > > > > > > > > either
> > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > using
> > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > your
> > > > > > > > > cpu
> > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > comprehensive
> > > > > > > > > > > use
> > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > easy
> > > > > > > > > > > to
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > your
> > > > > > > > > > > > control
> > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > parameter
> > > > > > > > > > > > and
> > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > is
> > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > you
> > > > > > > > > > > can
> > > > > > > > > > > > > use
> > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > most
> > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > For
> > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > execute a
> > > > > > > > > > > > line
> > > > > > > > > > > > > > of
> > > > > > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > > > > > running,
> > > > > > > > > > > > the
> > > > > > > > > > > > > > DROs
> > > > > > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > > > > > smooth
> > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > > > > > 100mSec,
> > > > > > > > > > > > so
> > > > > > > > > > > > > I
> > > > > > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > > > > > my
> > > > > > > > > > > > code,
> > > > > > > > > > > > > so
> > > > > > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > > > > > game.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > > > > > threads,
> > > > > > > > > > > > > I've
> > > > > > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > > > > > question
> > > > > > > > > > > > > > under
> > > > > > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > > > > > KMotionCNC,
> > > > > > > > > > > > > they
> > > > > > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > > > > > But,
> > > > > > > > > > > run
> > > > > > > > > > > > > them
> > > > > > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > > > > > and
> > > > > > > > > the
> > > > > > > > > > > > > > threads
> > > > > > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > > > > > lunch.
> > > > > > > > > > > > > KMotion
> > > > > > > > > > > > > > > confirms the threads remain running long after they should
> > > > > > > > have
> > > > > > > > > > > > > > terminated,
> > > > > > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > > > > > here's
> > > > > > > > > the
> > > > > > > > > > > > > > bizarre
> > > > > > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > > > > > open
> > > > > > > > > > > the
> > > > > > > > > > > > > app
> > > > > > > > > > > > > > -
> > > > > > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > > > > > correctly! If
> > > > > > > > > > > I
> > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > > > > > work
> > > > > > > > > > > > > > perfectly
> > > > > > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > > > > > message
> > > > > > > > > > > > to
> > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > > > > > MsgBox
> > > > > > > > > > > > > does
> > > > > > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > > > > > thread
> > > > > > > > > > > was
> > > > > > > > > > > > > > > launched from MY app!
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > > > > > my
> > > > > > > > > DSP
> > > > > > > > > > > > > > programs
> > > > > > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > > > > > when
> > > > > > > > > > > it
> > > > > > > > > > > > > did
> > > > > > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > > > > > that's
> > > > > > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > > > > > here...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3546 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Where is it getting tool data from them? It IS loading non-zero data from somewhere! The one advantage I see of using whatever mechanism is built into the interpreter is you can be more certain the data always gets loaded/re-loaded when it needs to.

But, as I said, I have already implemented my own tool-table mechanism that seems to work just fine.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Hello Ray,
>
>
>
> Tool file is not really implemented, but I plan to for people who want to use it.
>
>
>
> I never planned to use it so I created methods to populate the tool table programmatically.
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
> Sent: Thursday, January 26, 2012 11:27 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Tom,
>
> I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
>
> I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
>
> BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> >
> > Hi Guys,
> > Â
> > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail. And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > Â
> > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > Â
> > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already. WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic. The one exception is a WriteLine which sends a command that will take N ReadLines to get the response. In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up. So the WaitToken ReleaseToken can be used to avoid this problem.
> > Â
> > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > Â
> > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time. If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out. And in some cases this might even cause a dead lock.
> > Â
> > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works. If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread. So the Token prevents this as well.
> > Â
> > #2 I can't see how multiple threads would help the Screen Update rate in any way. Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work. But I can't see where anything would block while just trying to render the screen. The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something. But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> > Â
> > #3 I don't think multiple threads allows you to make use of multiple CPU cores. In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps). When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> >
> > Anyway, just some thoughts..
> > Thanks
> > TK
> > Â
> > Â
> >
> > ________________________________
> > From: bradodarb <bradodarb@>
> > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > Sent: Thursday, January 26, 2012 8:46 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> > Â
> >
> > Hello Ray,
> >
> > Yes, lock every call.
> >
> > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> >
> > looking forward to hearing back your results.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > >
> > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > >
> > > Regards,
> > > Ray L.
> > >
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Brad Murry <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > >
> > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > with the only goal of finding your problem.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Before that , you could try to surround any calls to the KM_Controller
> > > > instance with a lock clause. This will allow only one thread at a time to
> > > > access the controller object.
> > > >
> > > >
> > > >
> > > > Example::
> > > >
> > > >
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > var status = _Controller.WriteLineReadLine("Version");
> > > >
> > > >
> > > >
> > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > Basically, any function you are using the KM_Controller instance in may need
> > > > to be placed in a lock.
> > > >
> > > >
> > > >
> > > > Example2::
> > > >
> > > >
> > > >
> > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > >
> > > > {
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > //Do stuff with your controller here
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Try this and let me know if it helps. It is making sense to me that the
> > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > I never ran into it on MM as it never accesses the GUI thread.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ] On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > But perhaps a simple example:
> > > >
> > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > >
> > > > Some of the Button Click handlers also need to access things in
> > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > method in my dotNet "gasket" that handles all this.
> > > >
> > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > vice-versa. Or perhaps there's another/better option?
> > > >
> > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > that problem yet, since it appears to me only the DROs are actually
> > > > functional, and their operation is straight-forward (though I note you are
> > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > >
> > > > >
> > > > > I would probably need to see some code to be much help.
> > > > >
> > > > >
> > > > >
> > > > > Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > thread needs to access various dotNet data to create the updates. Right
> > > > now,
> > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > thread? Or is there a better way?
> > > > >
> > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > to
> > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > but
> > > > > doesn't exit.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > but,
> > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > still
> > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > called. Not sure I understand why that's happening.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > rendering
> > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > can
> > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > update
> > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > controls. I already update the DROs more often than the other
> > > > controls,
> > > > > by
> > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > ticks.
> > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > getting
> > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > since
> > > > > > > I have to go through an invoke to modify each control?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > > First off, you never want to have too many threads running,
> > > > > technically
> > > > > > > you
> > > > > > > > can only have one run per core and anything after that is going to
> > > > be
> > > > > time
> > > > > > > > slicing.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > HTML
> > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > earlier.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > loop
> > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > Within
> > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > and
> > > > > > > > when that happens I update the less important items.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > the
> > > > > > > DRO's
> > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > updated
> > > > > > > > every ½ a second.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > >
> > > > > > > > I can see how I could use parallel threads to make the display
> > > > updates
> > > > > > > more
> > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > concurrency
> > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > just
> > > > > > > > checked and my update loop is running only about 5X/second right
> > > > now,
> > > > > > > though
> > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > really
> > > > > > > > need to be sped up.
> > > > > > > >
> > > > > > > > How would you do it?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > a
> > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > to
> > > > > > > your
> > > > > > > > > middle layer.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > control
> > > > > > > > as
> > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > >
> > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > and
> > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > also
> > > > > > > > allows
> > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > test
> > > > > > > > the
> > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Gary,
> > > > > > > > > >
> > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > assume
> > > > > > > > > that
> > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > something
> > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > interact
> > > > > > > > with
> > > > > > > > > > the
> > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > can
> > > > > > > > either
> > > > > > > > > > use
> > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > using
> > > > > > > > > > .net4.0
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > your
> > > > > cpu
> > > > > > > > > usage
> > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > comprehensive
> > > > > > > use
> > > > > > > > > > > model.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > easy
> > > > > > > to
> > > > > > > > > use
> > > > > > > > > > to
> > > > > > > > > > > and easy to read.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > your
> > > > > > > > control
> > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > pseudo-example
> > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > parameter
> > > > > > > > and
> > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > is
> > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > thread
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > else
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > invocation required
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > you
> > > > > > > can
> > > > > > > > > use
> > > > > > > > > > > the above method like so::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > >
> > > > > > > > > > > //Example:
> > > > > > > > > > >
> > > > > > > > > > > lblXaxisDest.Text =
> > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > >
> > > > > > > > > > > }));
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > most
> > > > > > > > parts,
> > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > For
> > > > > > > > > > example,
> > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > execute a
> > > > > > > > line
> > > > > > > > > > of
> > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > running,
> > > > > > > > the
> > > > > > > > > > DROs
> > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > smooth
> > > > > > > > > > updates
> > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > 100mSec,
> > > > > > > > so
> > > > > > > > > I
> > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > my
> > > > > > > > code,
> > > > > > > > > so
> > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > game.
> > > > > > > > > > >
> > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > threads,
> > > > > > > > > I've
> > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > question
> > > > > > > > > > under
> > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > KMotionCNC,
> > > > > > > > > they
> > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > But,
> > > > > > > run
> > > > > > > > > them
> > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > and
> > > > > the
> > > > > > > > > > threads
> > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > lunch.
> > > > > > > > > KMotion
> > > > > > > > > > > confirms the threads remain running long after they should
> > > > have
> > > > > > > > > > terminated,
> > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > here's
> > > > > the
> > > > > > > > > > bizarre
> > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > open
> > > > > > > the
> > > > > > > > > app
> > > > > > > > > > -
> > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > correctly! If
> > > > > > > I
> > > > > > > > > > just
> > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > work
> > > > > > > > > > perfectly
> > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > message
> > > > > > > > to
> > > > > > > > > > the
> > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > MsgBox
> > > > > > > > > does
> > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > thread
> > > > > > > was
> > > > > > > > > > > launched from MY app!
> > > > > > > > > > >
> > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > my
> > > > > DSP
> > > > > > > > > > programs
> > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > when
> > > > > > > it
> > > > > > > > > did
> > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > that's
> > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > here...
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3547 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Tom,
>
> Did not know that was required.... I'll give it a try.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> >  
> > Regards
> > TK
> >
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Saturday, January 28, 2012 6:39 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > >
> > > main()
> > > {
> > > KM_Controller KM = new KM_Controller();
> > > Thread.Sleep(1000);
> > > GatherHex(0, 8);
> > > }
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad/Tom,
> > > >
> > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > >
> > > > Here's the code on my side:
> > > >
> > > > public String[] GatherHex(int offset, int words)
> > > > {
> > > > String[] ret = new String[words];
> > > > int lines = (words + 7) / 8;
> > > > String[] s = new String[lines];
> > > >
> > > > WaitToken();
> > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > for (int i = 0; i < lines; i++)
> > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > ReleaseToken();
> > > > int thisword = 0;
> > > > foreach (String t in s)
> > > > {
> > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > {
> > > > ret[thisword] = u;
> > > > if (++thisword == words)
> > > > break;
> > > > }
> > > > }
> > > > return ret;
> > > > }
> > > >
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > >
> > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > >
> > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > >
> > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > >
> > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Tom,
> > > > > >
> > > > > > OK, not using that.
> > > > > >
> > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > >  
> > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > >  
> > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > >  
> > > > > > > It is described in the latter half of this document
> > > > > > >  
> > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > >  
> > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > >  
> > > > > > > TK
> > > > > > >  
> > > > > > >  
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > > Tom,
> > > > > > >
> > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > >  
> > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > >  
> > > > > > > > Regards
> > > > > > > > TK
> > > > > > > >
> > > > > > > >
> > > > > > > > ________________________________
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >  
> > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > >
> > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Ray,
> > > > > > > > > ÃÆ'‚ 
> > > > > > > > > Yes.ÃÆ'‚  Everything.ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > ÃÆ'‚ 
> > > > > > > > > TK
> > > > > > > > >
> > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > ÃÆ'‚ 
> > > > > > > > > Tom,
> > > > > > > > >
> > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Ray,
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > Regards
> > > > > > > > > > TK
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > >
> > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > Brad,
> > > > > > > > > >
> > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > >
> > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > >
> > > > > > > > > > One new problem that has crept in:
> > > > > > > > > >
> > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > >
> > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > >
> > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Ray,
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > >
> > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > >
> > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > >
> > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > > > > > > > > > > > > > > most
> > > > > > > > > > > > > > > > > > > > > parts,
> > > > > > > > > > > > > > > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > > > > > > > > > > > > > > For
> > > > > > > > > > > > > > > > > > > > > > > example,
> > > > > > > > > > > > > > > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > > > > > > > > ><br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3548 From: himykabibble Date: 1/28/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Tom,
> >
> > Did not know that was required.... I'll give it a try.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > >  
> > > Regards
> > > TK
> > >
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Saturday, January 28, 2012 6:39 PM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > >
> > > > main()
> > > > {
> > > > KM_Controller KM = new KM_Controller();
> > > > Thread.Sleep(1000);
> > > > GatherHex(0, 8);
> > > > }
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad/Tom,
> > > > >
> > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > >
> > > > > Here's the code on my side:
> > > > >
> > > > > public String[] GatherHex(int offset, int words)
> > > > > {
> > > > > String[] ret = new String[words];
> > > > > int lines = (words + 7) / 8;
> > > > > String[] s = new String[lines];
> > > > >
> > > > > WaitToken();
> > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > for (int i = 0; i < lines; i++)
> > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > ReleaseToken();
> > > > > int thisword = 0;
> > > > > foreach (String t in s)
> > > > > {
> > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > {
> > > > > ret[thisword] = u;
> > > > > if (++thisword == words)
> > > > > break;
> > > > > }
> > > > > }
> > > > > return ret;
> > > > > }
> > > > >
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > >
> > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > >
> > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > >
> > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > >
> > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Tom,
> > > > > > >
> > > > > > > OK, not using that.
> > > > > > >
> > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > >  
> > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > >  
> > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > >  
> > > > > > > > It is described in the latter half of this document
> > > > > > > >  
> > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > >  
> > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > >  
> > > > > > > > TK
> > > > > > > >  
> > > > > > > >  
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >  
> > > > > > > > Tom,
> > > > > > > >
> > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Ray,
> > > > > > > > >  
> > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > >  
> > > > > > > > > Regards
> > > > > > > > > TK
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > ________________________________
> > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >  
> > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > >
> > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Ray,
> > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > Yes.ÃÆ'‚  Everything.ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > TK
> > > > > > > > > >
> > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > Tom,
> > > > > > > > > >
> > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Ray,
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > Regards
> > > > > > > > > > > TK
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > >
> > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > Brad,
> > > > > > > > > > >
> > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > >
> > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > >
> > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > >
> > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > >
> > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > >
> > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > //Example:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > lblXaxisDest.Text =
> > > > > > > > > > > > > > > > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }));
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > ><br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3549 From: bradodarb Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
That is marginally better, but remember your GUI was still locking for the duration of your code running inside the timer tick.

I still would not recommend anyone to use a timer for UI updating in .net. Timers were accepted in .net 1.0 but there are now many easy to use asynchronous methods of updating the UI.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> "#2 A separate GUI update thread is advantageous here because updating the data is taking <100ms at some times. If a timer is being used with say a 100ms interval and the task is taking 200ms then the GUI will be locked as the next timer ‘tick’ event will have been fired before the last was completed." - I actually dealt with this potential by stopping the timer at the top of the event handler, and starting it at the bottom.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> >
> > Tom,
> >
> >
> >
> > #1Good, but I suggested the lock to make sure we weren’t trying to grab a token from multiple threads. I think I understand that the token will be atomic and only be given to the calling thread but my thoughts were a lock will cause the next calling thread to wait until the other thread is done.
> >
> >
> >
> > #2 A separate GUI update thread is advantageous here because updating the data is taking <100ms at some times. If a timer is being used with say a 100ms interval and the task is taking 200ms then the GUI will be locked as the next timer ‘tick’ event will have been fired before the last was completed.
> >
> >
> >
> > By having the updating on a separate thread, the update process can take however long as is needed and update every cycle.
> >
> >
> >
> > #3 The Task Parallel library in .net 4.0 will distribute amongst cores when possible.
> >
> >
> >
> >
> >
> > Not saying the above is set in stone gospel(except 3), but is where I was coming from.
> >
> >
> >
> > -Brad Murry
> >
> >
> >
> > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of Tom Kerekes
> > Sent: Thursday, January 26, 2012 11:10 PM
> > To: DynoMotion@yahoogroups.com
> > Subject: Re: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Hi Guys,
> >
> >
> >
> > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail. And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> >
> >
> >
> > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> >
> >
> >
> > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already. WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic. The one exception is a WriteLine which sends a command that will take N ReadLines to get the response. In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up. So the WaitToken ReleaseToken can be used to avoid this problem.
> >
> >
> >
> > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> >
> >
> >
> > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time. If we aren't careful situations can happen where due to coincidence or circumstances one Thread gets completely or nearly completely locked out. And in some cases this might even cause a dead lock.
> >
> >
> >
> > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works. If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread. So the Token prevents this as well.
> >
> >
> >
> > #2 I can't see how multiple threads would help the Screen Update rate in any way. Multiple threads only help speed things up when something blocks so that while one thread is blocked another can wake up and do useful work. But I can't see where anything would block while just trying to render the screen. The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something. But even that should all be cached so I can't imagine why the screen couldn't be refreshed at 200 frames per second by a single thread.
> >
> >
> >
> > #3 I don't think multiple threads allows you to make use of multiple CPU cores. In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps). When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> >
> >
> > Anyway, just some thoughts..
> >
> > Thanks
> >
> > TK
> >
> >
> >
> >
> >
> > From: bradodarb <bradodarb@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Thursday, January 26, 2012 8:46 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >
> >
> >
> > Hello Ray,
> >
> > Yes, lock every call.
> >
> > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> >
> > looking forward to hearing back your results.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > >
> > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > >
> > > Regards,
> > > Ray L.
> > >
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Brad Murry <bradodarb@> wrote:
> > > >
> > > > Ray,
> > > >
> > > >
> > > >
> > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > with the only goal of finding your problem.
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Before that , you could try to surround any calls to the KM_Controller
> > > > instance with a lock clause. This will allow only one thread at a time to
> > > > access the controller object.
> > > >
> > > >
> > > >
> > > > Example::
> > > >
> > > >
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > var status = _Controller.WriteLineReadLine("Version");
> > > >
> > > >
> > > >
> > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > > Basically, any function you are using the KM_Controller instance in may need
> > > > to be placed in a lock.
> > > >
> > > >
> > > >
> > > > Example2::
> > > >
> > > >
> > > >
> > > > Public void MyUpdatingOrCommandingFunction(args….)
> > > >
> > > > {
> > > >
> > > > lock(_Controller)
> > > >
> > > > {
> > > >
> > > > //Do stuff with your controller here
> > > >
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Try this and let me know if it helps. It is making sense to me that the
> > > > KM_Controller is not Thread safe as it is maintaining pointer references….
> > > > I never ran into it on MM as it never accesses the GUI thread.
> > > >
> > > >
> > > >
> > > > -Brad Murry
> > > >
> > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ] On
> > > > Behalf Of himykabibble
> > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Brad,
> > > >
> > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > But perhaps a simple example:
> > > >
> > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > >
> > > > Some of the Button Click handlers also need to access things in
> > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > method in my dotNet "gasket" that handles all this.
> > > >
> > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > vice-versa. Or perhaps there's another/better option?
> > > >
> > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > that problem yet, since it appears to me only the DROs are actually
> > > > functional, and their operation is straight-forward (though I note you are
> > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ,
> > > > Brad Murry <bradodarb@> wrote:
> > > > >
> > > > > Hello Ray,
> > > > >
> > > > >
> > > > >
> > > > > I would probably need to see some code to be much help.
> > > > >
> > > > >
> > > > >
> > > > > Brad Murry
> > > > >
> > > > >
> > > > >
> > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ]
> > > > On
> > > > > Behalf Of himykabibble
> > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Brad,
> > > > >
> > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > thread needs to access various dotNet data to create the updates. Right
> > > > now,
> > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > thread? Or is there a better way?
> > > > >
> > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > to
> > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > but
> > > > > doesn't exit.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > but,
> > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > still
> > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > called. Not sure I understand why that's happening.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > Brad Murry <bradodarb@> wrote:
> > > > > > >
> > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > rendering
> > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > can
> > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > -Brad
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > On
> > > > > > > Behalf Of himykabibble
> > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > Brad,
> > > > > > >
> > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > update
> > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > controls. I already update the DROs more often than the other
> > > > controls,
> > > > > by
> > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > ticks.
> > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > getting
> > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > since
> > > > > > > I have to go through an invoke to modify each control?
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > >
> > > > > > > >
> > > > > > > > First off, you never want to have too many threads running,
> > > > > technically
> > > > > > > you
> > > > > > > > can only have one run per core and anything after that is going to
> > > > be
> > > > > time
> > > > > > > > slicing.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > HTML
> > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > earlier.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > loop
> > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > Within
> > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > and
> > > > > > > > when that happens I update the less important items.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > the
> > > > > > > DRO's
> > > > > > > > 1/10th a second and then things like LED's, enable status, etc… get
> > > > > > > updated
> > > > > > > > every ½ a second.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > -Brad Murry
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > On
> > > > > > > > Behalf Of himykabibble
> > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Brad,
> > > > > > > >
> > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > >
> > > > > > > > I can see how I could use parallel threads to make the display
> > > > updates
> > > > > > > more
> > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > concurrency
> > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > just
> > > > > > > > checked and my update loop is running only about 5X/second right
> > > > now,
> > > > > > > though
> > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > really
> > > > > > > > need to be sped up.
> > > > > > > >
> > > > > > > > How would you do it?
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > >
> > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > a
> > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > to
> > > > > > > your
> > > > > > > > > middle layer.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > control
> > > > > > > > as
> > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > -Brad
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > On
> > > > > > > > > Behalf Of himykabibble
> > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Brad,
> > > > > > > > >
> > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > >
> > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > and
> > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > also
> > > > > > > > allows
> > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > test
> > > > > > > > the
> > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > >
> > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > -Brad Murry
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > On
> > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Gary,
> > > > > > > > > >
> > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > assume
> > > > > > > > > that
> > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > something
> > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Ray,
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > interact
> > > > > > > > with
> > > > > > > > > > the
> > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > can
> > > > > > > > either
> > > > > > > > > > use
> > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > using
> > > > > > > > > > .net4.0
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > your
> > > > > cpu
> > > > > > > > > usage
> > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > comprehensive
> > > > > > > use
> > > > > > > > > > > model.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > easy
> > > > > > > to
> > > > > > > > > use
> > > > > > > > > > to
> > > > > > > > > > > and easy to read.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > your
> > > > > > > > control
> > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > pseudo-example
> > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > parameter
> > > > > > > > and
> > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > is
> > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > thread
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > else
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > invocation required
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > you
> > > > > > > can
> > > > > > > > > use
> > > > > > > > > > > the above method like so::
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > UpdateDocument(new Action(delegate()
> > > > > > > > > > >
> > > > > > > > > > > {
> > > > > > > > > > >
> > > > > > > > > > > //Put your control updating code here.
> > > > > > > > > > >
> > > > > > > > > > > //Example:
> > > > > > > > > > >
> > > > > > > > > > > lblXaxisDest.Text =
> > > > > _AxisContainer["X"].ActualPosition.ToString();
> > > > > > > > > > >
> > > > > > > > > > > }));
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > -Brad Murry
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > On
> > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > Sent: Wednesday, January 25, 2012 3:42 PM
> > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > Subject: [DynoMotion] Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > So, I've been exercising my app on the machine, and for the
> > > > most
> > > > > > > > parts,
> > > > > > > > > > > things are working OK, though it seems a bit "sluggish" to me.
> > > > > For
> > > > > > > > > > example,
> > > > > > > > > > > when I single-step, it takes a good 1/2 second or more to
> > > > > execute a
> > > > > > > > line
> > > > > > > > > > of
> > > > > > > > > > > G-code containing nothing more than a single comment. When
> > > > > running,
> > > > > > > > the
> > > > > > > > > > DROs
> > > > > > > > > > > update in significant increments, rather than the relatively
> > > > > smooth
> > > > > > > > > > updates
> > > > > > > > > > > I'm accustomed to with Mach3. I'm polling status at roughly
> > > > > 100mSec,
> > > > > > > > so
> > > > > > > > > I
> > > > > > > > > > > would expect it to appear smoother. Could still be problems in
> > > > > my
> > > > > > > > code,
> > > > > > > > > so
> > > > > > > > > > > none of this concerns me at all at this early stage of the
> > > > game.
> > > > > > > > > > >
> > > > > > > > > > > However, in working on the problem of the mis-executing DSP
> > > > > threads,
> > > > > > > > > I've
> > > > > > > > > > > discovered something really odd. I tested the two programs in
> > > > > > > question
> > > > > > > > > > under
> > > > > > > > > > > KMotionCNC, and am satisfied the code is correct - Under
> > > > > KMotionCNC,
> > > > > > > > > they
> > > > > > > > > > > both execute correctly first time, every time, without fail.
> > > > > But,
> > > > > > > run
> > > > > > > > > them
> > > > > > > > > > > under my app, using the few lines of code posted last night,
> > > > and
> > > > > the
> > > > > > > > > > threads
> > > > > > > > > > > start, may, or may not, make the first move, then go out to
> > > > > lunch.
> > > > > > > > > KMotion
> > > > > > > > > > > confirms the threads remain running long after they should
> > > > have
> > > > > > > > > > terminated,
> > > > > > > > > > > so they seem to be stuck waiting for..... something. Now,
> > > > here's
> > > > > the
> > > > > > > > > > bizarre
> > > > > > > > > > > part - If I open KMotionCNC - I don't do anything else, just
> > > > > open
> > > > > > > the
> > > > > > > > > app
> > > > > > > > > > -
> > > > > > > > > > > the thread immediately picks up and runs to completion
> > > > > correctly! If
> > > > > > > I
> > > > > > > > > > just
> > > > > > > > > > > leave KMotionCNC running alongside my app, both DSP programs
> > > > > work
> > > > > > > > > > perfectly
> > > > > > > > > > > every time. In addition, one of them uses a MsgBox to give a
> > > > > message
> > > > > > > > to
> > > > > > > > > > the
> > > > > > > > > > > user. If I have KMotionCNC minimized or otherwise hidden, this
> > > > > > > MsgBox
> > > > > > > > > does
> > > > > > > > > > > not appear UNTIL KMotionCNC get focus, even though the DSP
> > > > > thread
> > > > > > > was
> > > > > > > > > > > launched from MY app!
> > > > > > > > > > >
> > > > > > > > > > > What is going on here? What is KMotionCNC doing that affects
> > > > my
> > > > > DSP
> > > > > > > > > > programs
> > > > > > > > > > > in such a way? Why is the MsgBox seemingly tied to KMotionCNC,
> > > > > when
> > > > > > > it
> > > > > > > > > did
> > > > > > > > > > > NOT launch the threads? Is there some buffer or FIFO somewhere
> > > > > > > that's
> > > > > > > > > > > filling up and blocking communications? I'm at a total loss
> > > > > here...
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>
Group: DynoMotion Message: 3558 From: himykabibble Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Tom,
> > >
> > > Did not know that was required.... I'll give it a try.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Ray,
> > > >  
> > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > >  
> > > > Regards
> > > > TK
> > > >
> > > > From: himykabibble <jagboy@>
> > > > To: DynoMotion@yahoogroups.com
> > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > >  
> > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > >
> > > > > main()
> > > > > {
> > > > > KM_Controller KM = new KM_Controller();
> > > > > Thread.Sleep(1000);
> > > > > GatherHex(0, 8);
> > > > > }
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad/Tom,
> > > > > >
> > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > >
> > > > > > Here's the code on my side:
> > > > > >
> > > > > > public String[] GatherHex(int offset, int words)
> > > > > > {
> > > > > > String[] ret = new String[words];
> > > > > > int lines = (words + 7) / 8;
> > > > > > String[] s = new String[lines];
> > > > > >
> > > > > > WaitToken();
> > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > for (int i = 0; i < lines; i++)
> > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > ReleaseToken();
> > > > > > int thisword = 0;
> > > > > > foreach (String t in s)
> > > > > > {
> > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > {
> > > > > > ret[thisword] = u;
> > > > > > if (++thisword == words)
> > > > > > break;
> > > > > > }
> > > > > > }
> > > > > > return ret;
> > > > > > }
> > > > > >
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > >
> > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > >
> > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > >
> > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > >
> > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Tom,
> > > > > > > >
> > > > > > > > OK, not using that.
> > > > > > > >
> > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Ray,
> > > > > > > > >  
> > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > >  
> > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > >  
> > > > > > > > > It is described in the latter half of this document
> > > > > > > > >  
> > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > >  
> > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > >  
> > > > > > > > > TK
> > > > > > > > >  
> > > > > > > > >  
> > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >  
> > > > > > > > > Tom,
> > > > > > > > >
> > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Ray,
> > > > > > > > > >  
> > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > >  
> > > > > > > > > > Regards
> > > > > > > > > > TK
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > ________________________________
> > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >  
> > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > >
> > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Ray,
> > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > Yes.ÃÆ'‚  Everything.ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > TK
> > > > > > > > > > >
> > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > Tom,
> > > > > > > > > > >
> > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > Regards
> > > > > > > > > > > > TK
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > >
> > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > Brad,
> > > > > > > > > > > >
> > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > >
> > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > >
> > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > >
> > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > >
> > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > >
> > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > if (_GuiHost.Parent.InvokeRequired)//Tests to see if the call
> > > > > > > > > > > > > > > > > > > is
> > > > > > > > > > > > > > > > > > > > > > > > > > coming from a thread other than the GUI
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > _GuiHost.Parent.Invoke(action);//Merge action into the GUI
> > > > > > > > > > > > > > > > > > > > > > > > > > thread
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > else
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > action();//Came from the same thread as the GUI, so no
> > > > > > > > > > > > > > > > > > > > > > > > > > invocation required
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > In the updating method of whichever threading model you chose,
> > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > > the above method like so::
> > > > > > > > > > > > > > > > > > > > > > <br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3559 From: bradodarb Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
To each their own... but I did not write any gatherHex methods.


Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.

-Brad Murry

--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Brad,
>
> I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Tom,
> > > >
> > > > Did not know that was required.... I'll give it a try.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > >
> > > > > Hi Ray,
> > > > >  
> > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > >  
> > > > > Regards
> > > > > TK
> > > > >
> > > > > From: himykabibble <jagboy@>
> > > > > To: DynoMotion@yahoogroups.com
> > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > >
> > > > >
> > > > >  
> > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > >
> > > > > > main()
> > > > > > {
> > > > > > KM_Controller KM = new KM_Controller();
> > > > > > Thread.Sleep(1000);
> > > > > > GatherHex(0, 8);
> > > > > > }
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Brad/Tom,
> > > > > > >
> > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > >
> > > > > > > Here's the code on my side:
> > > > > > >
> > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > {
> > > > > > > String[] ret = new String[words];
> > > > > > > int lines = (words + 7) / 8;
> > > > > > > String[] s = new String[lines];
> > > > > > >
> > > > > > > WaitToken();
> > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > ReleaseToken();
> > > > > > > int thisword = 0;
> > > > > > > foreach (String t in s)
> > > > > > > {
> > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > {
> > > > > > > ret[thisword] = u;
> > > > > > > if (++thisword == words)
> > > > > > > break;
> > > > > > > }
> > > > > > > }
> > > > > > > return ret;
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > >
> > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > >
> > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > >
> > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > >
> > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Tom,
> > > > > > > > >
> > > > > > > > > OK, not using that.
> > > > > > > > >
> > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Ray,
> > > > > > > > > >  
> > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > >  
> > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > >  
> > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > >  
> > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > >  
> > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > >  
> > > > > > > > > > TK
> > > > > > > > > >  
> > > > > > > > > >  
> > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >  
> > > > > > > > > > Tom,
> > > > > > > > > >
> > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Ray,
> > > > > > > > > > >  
> > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > >  
> > > > > > > > > > > Regards
> > > > > > > > > > > TK
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > ________________________________
> > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >  
> > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > >
> > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > Yes.ÃÆ'‚  Everything.ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > TK
> > > > > > > > > > > >
> > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > Regards
> > > > > > > > > > > > > TK
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > Brad,
> > > > > > > > > > > > >
> > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > >
> > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > >
> > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > >
> > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > I would ditch the timer as well, using a service thread to
> > > > > > > > > > > > > > > > > > > > > interact
> > > > > > > > > > > > > > > > > > > > > > > > with
> > > > > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > > > kflop will be much smoother.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Instead of running your updates via your timer's callback you
> > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > > either
> > > > > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker or an Async Delegate or parallel task if
> > > > > > > > > > > > > > > > > > > > > using
> > > > > > > > > > > > > > > > > > > > > > > > > > .net4.0
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Parallel tasks are best because the will automagically load
> > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > cpu
> > > > > > > > > > > > > > > > > > > > > > > > > usage
> > > > > > > > > > > > > > > > > > > > > > > > > > > based on how many cores are available, etc.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Background workers are pretty easy to use and have a
> > > > > > > > > > > > > > > > > > > > > comprehensive
> > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > > > model.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Async delegates(using beginInvoke(IAsyncCallback, object) are
> > > > > > > > > > > > > > > > > > > > > easy
> > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > use
> > > > > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > > > and easy to read.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Whichever method you use, you will need to Invoke/Dispatch
> > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > > > > > updates when using Winforms/WPF respectively.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > It looks like you are using winforms, so here is a quick
> > > > > > > > > > > > > > > > > > > > > > > > pseudo-example
> > > > > > > > > > > > > > > > > > > > > > > > > > > where I am using a common method that takes an Action as a
> > > > > > > > > > > > > > > > > > > > > parameter
> > > > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > > > decides whether to invoke or not::
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > public void UpdateDocument(Action action)
> > > > > > > <br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3562 From: himykabibble Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

Probably D) All of the above. I must admit, this has been a very frustrating experience at times. But I certainly don't mean to complain, and I apologize if I've come across that way. It's probably just my frustration and exhaustion coming out in the very imperfect communications means of e-mail. I think dotNet is a wonderful thing, and there's no other way I'd be able to build my own CNC controller app without it. And I know once I get the last few kinks out, this thing is going to make running my machine much more enjoyable.

I am not a professional software developer, and this is my first serious foray into Windows app development, c#, .NET and many other things. I am rather overwhelmed, not only by all the totally unrelated "real" work I have to get done every day, but by how much information I've had to absorb to make it this far with my app. I am, quite frankly, in information overload. You and Tom are FAR deeper into it than I am, and far, far, FAR more experienced at software development than me, so things that are obvious to you, are not always to me. Looking at the existing code does not always lead me to an answer, especially when it means digging into the bowels of the interpreter or KMotionCNC. Then I run face-first into something like the current problem where writing a single, specific Persist Var crashes the whole system, and I'm dead in the water, because I don't have the means to dig into it any further and figure out what's really going on there.

My app is now so close to working, I can taste it, but it's been stuck at that point for the last week or more. It's close, but not quite close enough. I'm just groping around in the dark, trying to figure how this all works, and understand enough to do what I need to do, often with very little information to go on. And some of what I do have is confusing/conflicting.

I suppose my question was mostly about the long-term philosophy of dotNet. The DLL APIs obviously work just fine, but there are quite a few operations that are not at all obvious, until you find the right piece of magic code to make it work. One example is FeedHold. There's no way anyone could look at the APIs and know how to implement that, even though it's a few simple lines of code. It seems to me there is an opportunity to make it easier for us numb-nuts to understand and work with by doing somewhat more than just a literal translation of the underlying DLL APIs. I'm curious if you will take it in that direction.

As a numb-nuts user, I can tell you what's there can be very confusing, and, to me, seemingly illogical in places. For example, the fact that we have to specify axis parameters in at least three different places. And there are several places with methods or properties called "Halt", or something similar. I am clueless as to how to use these, and how they all interact, if at all. I find myself sifting through the various layers and objects trying to find something that sounds like what I need, and sometimes when I do find it, I wonder "Why is it there?". I'm certain there's always a good reason for it, but I can't always see it. Then when I need it again in the future, I have to go through the whole process again. What I'm trying to do in my "gasket" is provide simple, high-level APIs to the app, so it need not know or care HOW things work, they just do. So, you call a method named "DoThis", and it does this, leaving the GUI to be just a GUI. Seems to me dotNet, would really benefit from something like that, to make the whole system much more "approachable" to more casual users, and hide the not inconsiderable complexities of the DLL APIs from the user. Any plans to take it more that direction?

Regards,
Ray L.



--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> To each their own... but I did not write any gatherHex methods.
>
>
> Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.
>
> -Brad Murry
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Brad,
> >
> > I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Tom,
> > > > >
> > > > > Did not know that was required.... I'll give it a try.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > >
> > > > > > Hi Ray,
> > > > > >  
> > > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > > >  
> > > > > > Regards
> > > > > > TK
> > > > > >
> > > > > > From: himykabibble <jagboy@>
> > > > > > To: DynoMotion@yahoogroups.com
> > > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > >
> > > > > >
> > > > > >  
> > > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > > >
> > > > > > > main()
> > > > > > > {
> > > > > > > KM_Controller KM = new KM_Controller();
> > > > > > > Thread.Sleep(1000);
> > > > > > > GatherHex(0, 8);
> > > > > > > }
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Brad/Tom,
> > > > > > > >
> > > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > > >
> > > > > > > > Here's the code on my side:
> > > > > > > >
> > > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > > {
> > > > > > > > String[] ret = new String[words];
> > > > > > > > int lines = (words + 7) / 8;
> > > > > > > > String[] s = new String[lines];
> > > > > > > >
> > > > > > > > WaitToken();
> > > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > > ReleaseToken();
> > > > > > > > int thisword = 0;
> > > > > > > > foreach (String t in s)
> > > > > > > > {
> > > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > > {
> > > > > > > > ret[thisword] = u;
> > > > > > > > if (++thisword == words)
> > > > > > > > break;
> > > > > > > > }
> > > > > > > > }
> > > > > > > > return ret;
> > > > > > > > }
> > > > > > > >
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > > >
> > > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > > >
> > > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > > >
> > > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > > >
> > > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Tom,
> > > > > > > > > >
> > > > > > > > > > OK, not using that.
> > > > > > > > > >
> > > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Hi Ray,
> > > > > > > > > > >  
> > > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > > >  
> > > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > > >  
> > > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > > >  
> > > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > > >  
> > > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > > >  
> > > > > > > > > > > TK
> > > > > > > > > > >  
> > > > > > > > > > >  
> > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > >  
> > > > > > > > > > > Tom,
> > > > > > > > > > >
> > > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > >  
> > > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > > >  
> > > > > > > > > > > > Regards
> > > > > > > > > > > > TK
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > ________________________________
> > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >  
> > > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > > >
> > > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > Yes.ÃÆ'‚  Everything.ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > TK
> > > > > > > > > > > > >
> > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > Tom,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the screen.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Absolutely, you can push from wherever, but you will need to pass
> > > > > > > > > > > > > > > > > > > > > a
> > > > > > > > > > > > > > > > > > > > > > > > > > reference to a control you are using(best bet is the main window)
> > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > your
> > > > > > > > > > > > > > > > > > > > > > > > > > middle layer.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > If you used WPF you would not need to maintain a reference to any
> > > > > > > > > > > > > > > > > > > > > > > > control
> > > > > > > > > > > > > > > > > > > > > > > > > as
> > > > > > > > > > > > > > > > > > > > > > > > > > you could walk up the tree to the current Dispatcher.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:14 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Sorry - too many projects, too many people.... :-)
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I have a layer between my GUI and dotNet, to keep the GUI "clean"
> > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > > high-level. All communications passes through that layer, and it
> > > > > > > > > > > > > > > > > > > > > > also
> > > > > > > > > > > > > > > > > > > > > > > > > allows
> > > > > > > > > > > > > > > > > > > > > > > > > > me to pull dotNet out, and replace the gasket with a simulator, to
> > > > > > > > > > > > > > > > > > > > > > test
> > > > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > > GUI stand-alone, and force all the possible states.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Who you calling Gary? ;)
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Clarify KM"gasket" please.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 5:34 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre)
> > > > > > > > > > > > > > > > > > > > > Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Gary,
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > I noted the " _GuiHost.Parent.Invoke(action)" in your example. I
> > > > > > > > > > > > > > > > > > > > > > > > assume
> > > > > > > > > > > > > > > > > > > > > > > > > > that
> > > > > > > > > > > > > > > > > > > > > > > > > > > could be used to push GUI updates from my KM "gasket" when
> > > > > > > > > > > > > > > > > > > > > > something
> > > > > > > > > > > > > > > > > > > > > > > > > > > changes, rather than pulling them from the main app, right?
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@<br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3564 From: Tom Kerekes Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hi Ray,
 
Just wanted to point out how much I personally appreciate the effort, work, feedback, persistence, and patience you have even though you are a bit overly candid at times :}
 
I'm not sure you are aware, but when you do come across a function that crashes or fails it is possible to step right into it and enter the C++ libraries all the way to the bottom to see what is wrong. I find it very instructional as well.  Sometimes you need to turn on the "debug unmanaged code" option and target things to the debug directory but I find it well worth the trouble.
 
Regarding the axis parameters in 3 places that you've mentioned several times, where is that?  I think it might be two places.  One set of motion profile parameters of Accelerations and Velocities is for the 2nd order coordinated motion trajectory planner.  The other is the Jerk, Acceleration, and Velocity parameters used within KFLOP for independent 3rd order motions.  These are really two different things and it really is best to keep them separate.
 
A lot of the things we are doing really are complicated so the concept of things should be as simple as possible but no simpler often comes into play.  The tendency for everyone is to just expect things to be numb-nuts simple and be frustrated when they aren't is common.  But certainly much could be improved so suggestions are appreciated especially if they are specific.
 
Thanks
TK
 
 
 

Group: DynoMotion Message: 3565 From: himykabibble Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Tom,

Thanks. I really do appreciate all the help you and Brad have provided. I'm sorry if my frustration shows at time. I'm sure you'll both be glad when I'm done, and I quit pestering you both! :-)

As for axis parameters, right now we need to put them into the Init.c, and, in dotNet, they get written to both CoordMotion and Interpreter. Now, perhaps it's not *necessary* to do that, but that's what the code I copied does (from your example), and I don't understand it enough to modify it. I can post what I've got, if you want to look at it. There are also several other parameters that I have no clue what they are, or what to set them to that I'll need to ask about soon.

I think what I'm going to do is put all the config information in one place - a config file managed by the app - then download it to the DSP from there on init.

I was not aware I could step through the DLLs. It doesn't work with the current configuration, but I'll try what you suggested, and see if I can get to the bottom of the crashes. Though, unfortunately, the current problem in clearing the PC_COMM command word seems to have a side-effect that causes the crash to occur sometime later, which could be a bugger to find. I have figured out one small piece - the screenful of error dialogs I get is coming out of my re-init code, which says the board is say it's connected, but I get an error when I try to compile and load my init.c. Since the board and/or DLL seems to be hosed at that point (I have to power cycle the board to get things working again - just killing and re-starting the app won't do it), that makes sense.

As for simplicity, I understand there is a lot of complexity in there, but what I'm suggesting is a few additional APIs that I suspect would make life easier for 95% of potential users. And, perhaps, just making common operations more obvious. Right now, you've exposed "Expert Mode". Even some more basic, clearly documented examples would make proper usage much easier to understand. I would be happy to volunteer my app for the purpose, and/or my "gasket" layer as a starting point. As I said, the point of the gasket layer is to provide the bulk of the functionality required for a CNC app, like KMotionCNC, with mostly only the GUI elements missing. I'd even be willing to document the hell out of them, so other idiots like me could easily understand how to modify them. It is all dead-simple code (otherwise, I'd never remember how it works....). Though I suspect you'd both run out of the room screaming if you saw some of my code, at least in its current state.... :-)

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@...> wrote:
>
> Hi Ray,
>  
> Just wanted to point out how much I personally appreciate the effort, work, feedback, persistence, and patience you have even though you are a bit overly candid at times :}
>  
> I'm not sure you are aware, but when you do come across a function that crashes or fails it is possible to step right into it and enter the C++ libraries all the way to the bottom to see what is wrong. I find it very instructional as well.  Sometimes you need to turn on the "debug unmanaged code" option and target things to the debug directory but I find it well worth the trouble.
>  
> Regarding the axis parameters in 3 places that you've mentioned several times, where is that?  I think it might be two places.  One set of motion profile parameters of Accelerations and Velocities is for the 2nd order coordinated motion trajectory planner.  The other is the Jerk, Acceleration, and Velocity parameters used within KFLOP for independent 3rd order motions.  These are really two different things and it really is best to keep them separate.
>  
> A lot of the things we are doing really are complicated so the concept of things should be as simple as possible but no simpler often comes into play.  The tendency for everyone is to just expect things to be numb-nuts simple and be frustrated when they aren't is common.  But certainly much could be improved so suggestions are appreciated especially if they are specific.
>  
> Thanks
> TK
>  
>  
>  
>
> From: himykabibble <jagboy@...>
> To: DynoMotion@yahoogroups.com
> Sent: Sunday, January 29, 2012 1:02 PM
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>  
> Brad,
>
> Probably D) All of the above. I must admit, this has been a very frustrating experience at times. But I certainly don't mean to complain, and I apologize if I've come across that way. It's probably just my frustration and exhaustion coming out in the very imperfect communications means of e-mail. I think dotNet is a wonderful thing, and there's no other way I'd be able to build my own CNC controller app without it. And I know once I get the last few kinks out, this thing is going to make running my machine much more enjoyable.
>
> I am not a professional software developer, and this is my first serious foray into Windows app development, c#, .NET and many other things. I am rather overwhelmed, not only by all the totally unrelated "real" work I have to get done every day, but by how much information I've had to absorb to make it this far with my app. I am, quite frankly, in information overload. You and Tom are FAR deeper into it than I am, and far, far, FAR more experienced at software development than me, so things that are obvious to you, are not always to me. Looking at the existing code does not always lead me to an answer, especially when it means digging into the bowels of the interpreter or KMotionCNC. Then I run face-first into something like the current problem where writing a single, specific Persist Var crashes the whole system, and I'm dead in the water, because I don't have the means to dig into it any further and figure out what's really going on there.
>
> My app is now so close to working, I can taste it, but it's been stuck at that point for the last week or more. It's close, but not quite close enough. I'm just groping around in the dark, trying to figure how this all works, and understand enough to do what I need to do, often with very little information to go on. And some of what I do have is confusing/conflicting.
>
> I suppose my question was mostly about the long-term philosophy of dotNet. The DLL APIs obviously work just fine, but there are quite a few operations that are not at all obvious, until you find the right piece of magic code to make it work. One example is FeedHold. There's no way anyone could look at the APIs and know how to implement that, even though it's a few simple lines of code. It seems to me there is an opportunity to make it easier for us numb-nuts to understand and work with by doing somewhat more than just a literal translation of the underlying DLL APIs. I'm curious if you will take it in that direction.
>
> As a numb-nuts user, I can tell you what's there can be very confusing, and, to me, seemingly illogical in places. For example, the fact that we have to specify axis parameters in at least three different places. And there are several places with methods or properties called "Halt", or something similar. I am clueless as to how to use these, and how they all interact, if at all. I find myself sifting through the various layers and objects trying to find something that sounds like what I need, and sometimes when I do find it, I wonder "Why is it there?". I'm certain there's always a good reason for it, but I can't always see it. Then when I need it again in the future, I have to go through the whole process again. What I'm trying to do in my "gasket" is provide simple, high-level APIs to the app, so it need not know or care HOW things work, they just do. So, you call a method named "DoThis", and it does this, leaving the GUI to be just a GUI. Seems to me
> dotNet, would really benefit from something like that, to make the whole system much more "approachable" to more casual users, and hide the not inconsiderable complexities of the DLL APIs from the user. Any plans to take it more that direction?
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> >
> > To each their own... but I did not write any gatherHex methods.
> >
> >
> > Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.
> >
> > -Brad Murry
> >
> > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > >
> > > Brad,
> > >
> > > I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Tom,
> > > > > >
> > > > > > Did not know that was required.... I'll give it a try.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > >
> > > > > > > Hi Ray,
> > > > > > >  
> > > > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > > > >  
> > > > > > > Regards
> > > > > > > TK
> > > > > > >
> > > > > > > From: himykabibble <jagboy@>
> > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > >
> > > > > > >
> > > > > > >  
> > > > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > > > >
> > > > > > > > main()
> > > > > > > > {
> > > > > > > > KM_Controller KM = new KM_Controller();
> > > > > > > > Thread.Sleep(1000);
> > > > > > > > GatherHex(0, 8);
> > > > > > > > }
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Brad/Tom,
> > > > > > > > >
> > > > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > > > >
> > > > > > > > > Here's the code on my side:
> > > > > > > > >
> > > > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > > > {
> > > > > > > > > String[] ret = new String[words];
> > > > > > > > > int lines = (words + 7) / 8;
> > > > > > > > > String[] s = new String[lines];
> > > > > > > > >
> > > > > > > > > WaitToken();
> > > > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > > > ReleaseToken();
> > > > > > > > > int thisword = 0;
> > > > > > > > > foreach (String t in s)
> > > > > > > > > {
> > > > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > > > {
> > > > > > > > > ret[thisword] = u;
> > > > > > > > > if (++thisword == words)
> > > > > > > > > break;
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > return ret;
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > > > >
> > > > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > > > >
> > > > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > > > >
> > > > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > > > >
> > > > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Tom,
> > > > > > > > > > >
> > > > > > > > > > > OK, not using that.
> > > > > > > > > > >
> > > > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > >  
> > > > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > > > >  
> > > > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > > > >  
> > > > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > > > >  
> > > > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > > > >  
> > > > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > > > >  
> > > > > > > > > > > > TK
> > > > > > > > > > > >  
> > > > > > > > > > > >  
> > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > >  
> > > > > > > > > > > > Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > Regards
> > > > > > > > > > > > > TK
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > > > >
> > > > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > Yes.ÃÆ'Æ'‚ÃÆ'‚  Everything.ÃÆ'Æ'‚ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'Æ'‚ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > TK
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed
> reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the
> screen.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > > > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 6:49 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I'm not changing to WPF at this late stage of the game! :-)
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I can see how I could use parallel threads to make the display
> > > > > > > > > > > > > > > > > > > > > > updates
> > > > > > > > > > > > > > > > > > > > > > > > > more
> > > > > > > > > > > > > > > > > > > > > > > > > > efficient (launch separate threads to update all the DROs, and other
> > > > > > > > > > > > > > > > > > > > > > > > > > controls). I assume the wonders of .NET will deal with all the
> > > > > > > > > > > > > > > > > > > > > > > concurrency
> > > > > > > > > > > > > > > > > > > > > > > > > > issues that could create in accessing especially dotNet objects? I
> > > > > > > > > > > > > > > > > > > > > > > just
> > > > > > > > > > > > > > > > > > > > > > > > > > checked and my update loop is running only about 5X/second right
> > > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > > > though
> > > > > > > > > > > > > > > > > > > > > > > > > > GUI response is generally not bad. It's mostly the DRO updates that
> > > > > > > > > > > > > > > > > > > > > > > really
> > > > > > > > > > > > > > > > > > > > > > > > > > need to be sped up.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > How would you do it?
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > ><br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3566 From: bradodarb Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Hello Ray,

I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally.

I also second Tom's statement that all of your efforts are greatly appreciated. I plan to use the .net wrappers for my own projects soon so working with you and others to squash the bugs early on is a huge benefit and I am quite grateful. I tend to agree with you that there are some areas that the API's(c++ as well as .net) can be much improved, unified and simplified. The .net API is relatively new and unproven, so my primary goal is get things working reliably as they are for now. Once things are stable we can add some syntactic sugar.

I'm not here to tell anyone how to act, but it would be more productive if you could also summarize what you are after in your post so I can help you and others(including myself) to make the API better.

For example, I am trying to put a list of bug fixes and feature requests together and it is a bit difficult to sift through the group posts to form a concise plan. Maybe what we really need is an area for bug reports and feature requests…..

At any rate, keep the feedback coming- however colorful you would like to make it and help me out by dumbing down what you are after so I can help.

-Brad Murry


--- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@...> wrote:
>
> Tom,
>
> Thanks. I really do appreciate all the help you and Brad have provided. I'm sorry if my frustration shows at time. I'm sure you'll both be glad when I'm done, and I quit pestering you both! :-)
>
> As for axis parameters, right now we need to put them into the Init.c, and, in dotNet, they get written to both CoordMotion and Interpreter. Now, perhaps it's not *necessary* to do that, but that's what the code I copied does (from your example), and I don't understand it enough to modify it. I can post what I've got, if you want to look at it. There are also several other parameters that I have no clue what they are, or what to set them to that I'll need to ask about soon.
>
> I think what I'm going to do is put all the config information in one place - a config file managed by the app - then download it to the DSP from there on init.
>
> I was not aware I could step through the DLLs. It doesn't work with the current configuration, but I'll try what you suggested, and see if I can get to the bottom of the crashes. Though, unfortunately, the current problem in clearing the PC_COMM command word seems to have a side-effect that causes the crash to occur sometime later, which could be a bugger to find. I have figured out one small piece - the screenful of error dialogs I get is coming out of my re-init code, which says the board is say it's connected, but I get an error when I try to compile and load my init.c. Since the board and/or DLL seems to be hosed at that point (I have to power cycle the board to get things working again - just killing and re-starting the app won't do it), that makes sense.
>
> As for simplicity, I understand there is a lot of complexity in there, but what I'm suggesting is a few additional APIs that I suspect would make life easier for 95% of potential users. And, perhaps, just making common operations more obvious. Right now, you've exposed "Expert Mode". Even some more basic, clearly documented examples would make proper usage much easier to understand. I would be happy to volunteer my app for the purpose, and/or my "gasket" layer as a starting point. As I said, the point of the gasket layer is to provide the bulk of the functionality required for a CNC app, like KMotionCNC, with mostly only the GUI elements missing. I'd even be willing to document the hell out of them, so other idiots like me could easily understand how to modify them. It is all dead-simple code (otherwise, I'd never remember how it works....). Though I suspect you'd both run out of the room screaming if you saw some of my code, at least in its current state.... :-)
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> >
> > Hi Ray,
> >  
> > Just wanted to point out how much I personally appreciate the effort, work, feedback, persistence, and patience you have even though you are a bit overly candid at times :}
> >  
> > I'm not sure you are aware, but when you do come across a function that crashes or fails it is possible to step right into it and enter the C++ libraries all the way to the bottom to see what is wrong. I find it very instructional as well.  Sometimes you need to turn on the "debug unmanaged code" option and target things to the debug directory but I find it well worth the trouble.
> >  
> > Regarding the axis parameters in 3 places that you've mentioned several times, where is that?  I think it might be two places.  One set of motion profile parameters of Accelerations and Velocities is for the 2nd order coordinated motion trajectory planner.  The other is the Jerk, Acceleration, and Velocity parameters used within KFLOP for independent 3rd order motions.  These are really two different things and it really is best to keep them separate.
> >  
> > A lot of the things we are doing really are complicated so the concept of things should be as simple as possible but no simpler often comes into play.  The tendency for everyone is to just expect things to be numb-nuts simple and be frustrated when they aren't is common.  But certainly much could be improved so suggestions are appreciated especially if they are specific.
> >  
> > Thanks
> > TK
> >  
> >  
> >  
> >
> > From: himykabibble <jagboy@>
> > To: DynoMotion@yahoogroups.com
> > Sent: Sunday, January 29, 2012 1:02 PM
> > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> >
> >
> >  
> > Brad,
> >
> > Probably D) All of the above. I must admit, this has been a very frustrating experience at times. But I certainly don't mean to complain, and I apologize if I've come across that way. It's probably just my frustration and exhaustion coming out in the very imperfect communications means of e-mail. I think dotNet is a wonderful thing, and there's no other way I'd be able to build my own CNC controller app without it. And I know once I get the last few kinks out, this thing is going to make running my machine much more enjoyable.
> >
> > I am not a professional software developer, and this is my first serious foray into Windows app development, c#, .NET and many other things. I am rather overwhelmed, not only by all the totally unrelated "real" work I have to get done every day, but by how much information I've had to absorb to make it this far with my app. I am, quite frankly, in information overload. You and Tom are FAR deeper into it than I am, and far, far, FAR more experienced at software development than me, so things that are obvious to you, are not always to me. Looking at the existing code does not always lead me to an answer, especially when it means digging into the bowels of the interpreter or KMotionCNC. Then I run face-first into something like the current problem where writing a single, specific Persist Var crashes the whole system, and I'm dead in the water, because I don't have the means to dig into it any further and figure out what's really going on there.
> >
> > My app is now so close to working, I can taste it, but it's been stuck at that point for the last week or more. It's close, but not quite close enough. I'm just groping around in the dark, trying to figure how this all works, and understand enough to do what I need to do, often with very little information to go on. And some of what I do have is confusing/conflicting.
> >
> > I suppose my question was mostly about the long-term philosophy of dotNet. The DLL APIs obviously work just fine, but there are quite a few operations that are not at all obvious, until you find the right piece of magic code to make it work. One example is FeedHold. There's no way anyone could look at the APIs and know how to implement that, even though it's a few simple lines of code. It seems to me there is an opportunity to make it easier for us numb-nuts to understand and work with by doing somewhat more than just a literal translation of the underlying DLL APIs. I'm curious if you will take it in that direction.
> >
> > As a numb-nuts user, I can tell you what's there can be very confusing, and, to me, seemingly illogical in places. For example, the fact that we have to specify axis parameters in at least three different places. And there are several places with methods or properties called "Halt", or something similar. I am clueless as to how to use these, and how they all interact, if at all. I find myself sifting through the various layers and objects trying to find something that sounds like what I need, and sometimes when I do find it, I wonder "Why is it there?". I'm certain there's always a good reason for it, but I can't always see it. Then when I need it again in the future, I have to go through the whole process again. What I'm trying to do in my "gasket" is provide simple, high-level APIs to the app, so it need not know or care HOW things work, they just do. So, you call a method named "DoThis", and it does this, leaving the GUI to be just a GUI. Seems to me
> > dotNet, would really benefit from something like that, to make the whole system much more "approachable" to more casual users, and hide the not inconsiderable complexities of the DLL APIs from the user. Any plans to take it more that direction?
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > >
> > > To each their own... but I did not write any gatherHex methods.
> > >
> > >
> > > Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.
> > >
> > > -Brad Murry
> > >
> > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > >
> > > > Brad,
> > > >
> > > > I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Tom,
> > > > > > >
> > > > > > > Did not know that was required.... I'll give it a try.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > >
> > > > > > > > Hi Ray,
> > > > > > > >  
> > > > > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > > > > >  
> > > > > > > > Regards
> > > > > > > > TK
> > > > > > > >
> > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > >
> > > > > > > >
> > > > > > > >  
> > > > > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > > > > >
> > > > > > > > > main()
> > > > > > > > > {
> > > > > > > > > KM_Controller KM = new KM_Controller();
> > > > > > > > > Thread.Sleep(1000);
> > > > > > > > > GatherHex(0, 8);
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Brad/Tom,
> > > > > > > > > >
> > > > > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > > > > >
> > > > > > > > > > Here's the code on my side:
> > > > > > > > > >
> > > > > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > > > > {
> > > > > > > > > > String[] ret = new String[words];
> > > > > > > > > > int lines = (words + 7) / 8;
> > > > > > > > > > String[] s = new String[lines];
> > > > > > > > > >
> > > > > > > > > > WaitToken();
> > > > > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > > > > ReleaseToken();
> > > > > > > > > > int thisword = 0;
> > > > > > > > > > foreach (String t in s)
> > > > > > > > > > {
> > > > > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > > > > {
> > > > > > > > > > ret[thisword] = u;
> > > > > > > > > > if (++thisword == words)
> > > > > > > > > > break;
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > > return ret;
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > > > > >
> > > > > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > > > > >
> > > > > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > > > > >
> > > > > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > > > > >
> > > > > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > OK, not using that.
> > > > > > > > > > > >
> > > > > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > >  
> > > > > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > > > > >  
> > > > > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > > > > >  
> > > > > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > > > > >  
> > > > > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > > > > >  
> > > > > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > > > > >  
> > > > > > > > > > > > > TK
> > > > > > > > > > > > >  
> > > > > > > > > > > > >  
> > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > >
> > > > > > > > > > > > >
> > > > > > > > > > > > >  
> > > > > > > > > > > > > Tom,
> > > > > > > > > > > > >
> > > > > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > TK
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > Yes.ÃÆ'Æ'‚ÃÆ'‚  Everything.ÃÆ'Æ'‚ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'Æ'‚ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed
> > reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the
> > screen.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > > > > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Very basic setup that only uses one additional thread that updates
> > > > > > > > > > > > > > > > > > > > > > > the
> > > > > > > > > > > > > > > > > > > > > > > > > > DRO's
> > > > > > > > > > > > > > > > > > > > > > > > > > > 1/10th a second and then things like LED's, enable status, etcÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦ get
> > > > > > > > > > > > > > > > > > > > > > > > > > updated
> > > > > > > > > > > > > > > > > > > > > > > > > > > every ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚½ a second.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > I will re-upload my source so you can see how it works.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > ><br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3567 From: himykabibble Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

"I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally." - Who am I to complain! :-)

I'm more than happy to move to a different venue, or method of communication, if it'll make it easier to track things. I'm really not a fan of the Yahoo forums - like you said, it's impossible to track information here. Finding a post you KNOW you read a week ago can take forever.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello Ray,
>
> I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally.
>
> I also second Tom's statement that all of your efforts are greatly appreciated. I plan to use the .net wrappers for my own projects soon so working with you and others to squash the bugs early on is a huge benefit and I am quite grateful. I tend to agree with you that there are some areas that the API's(c++ as well as .net) can be much improved, unified and simplified. The .net API is relatively new and unproven, so my primary goal is get things working reliably as they are for now. Once things are stable we can add some syntactic sugar.
>
> I'm not here to tell anyone how to act, but it would be more productive if you could also summarize what you are after in your post so I can help you and others(including myself) to make the API better.
>
> For example, I am trying to put a list of bug fixes and feature requests together and it is a bit difficult to sift through the group posts to form a concise plan. Maybe what we really need is an area for bug reports and feature requests…..
>
> At any rate, keep the feedback coming- however colorful you would like to make it and help me out by dumbing down what you are after so I can help.
>
> -Brad Murry
>
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Tom,
> >
> > Thanks. I really do appreciate all the help you and Brad have provided. I'm sorry if my frustration shows at time. I'm sure you'll both be glad when I'm done, and I quit pestering you both! :-)
> >
> > As for axis parameters, right now we need to put them into the Init.c, and, in dotNet, they get written to both CoordMotion and Interpreter. Now, perhaps it's not *necessary* to do that, but that's what the code I copied does (from your example), and I don't understand it enough to modify it. I can post what I've got, if you want to look at it. There are also several other parameters that I have no clue what they are, or what to set them to that I'll need to ask about soon.
> >
> > I think what I'm going to do is put all the config information in one place - a config file managed by the app - then download it to the DSP from there on init.
> >
> > I was not aware I could step through the DLLs. It doesn't work with the current configuration, but I'll try what you suggested, and see if I can get to the bottom of the crashes. Though, unfortunately, the current problem in clearing the PC_COMM command word seems to have a side-effect that causes the crash to occur sometime later, which could be a bugger to find. I have figured out one small piece - the screenful of error dialogs I get is coming out of my re-init code, which says the board is say it's connected, but I get an error when I try to compile and load my init.c. Since the board and/or DLL seems to be hosed at that point (I have to power cycle the board to get things working again - just killing and re-starting the app won't do it), that makes sense.
> >
> > As for simplicity, I understand there is a lot of complexity in there, but what I'm suggesting is a few additional APIs that I suspect would make life easier for 95% of potential users. And, perhaps, just making common operations more obvious. Right now, you've exposed "Expert Mode". Even some more basic, clearly documented examples would make proper usage much easier to understand. I would be happy to volunteer my app for the purpose, and/or my "gasket" layer as a starting point. As I said, the point of the gasket layer is to provide the bulk of the functionality required for a CNC app, like KMotionCNC, with mostly only the GUI elements missing. I'd even be willing to document the hell out of them, so other idiots like me could easily understand how to modify them. It is all dead-simple code (otherwise, I'd never remember how it works....). Though I suspect you'd both run out of the room screaming if you saw some of my code, at least in its current state.... :-)
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > Just wanted to point out how much I personally appreciate the effort, work, feedback, persistence, and patience you have even though you are a bit overly candid at times :}
> > >  
> > > I'm not sure you are aware, but when you do come across a function that crashes or fails it is possible to step right into it and enter the C++ libraries all the way to the bottom to see what is wrong. I find it very instructional as well.  Sometimes you need to turn on the "debug unmanaged code" option and target things to the debug directory but I find it well worth the trouble.
> > >  
> > > Regarding the axis parameters in 3 places that you've mentioned several times, where is that?  I think it might be two places.  One set of motion profile parameters of Accelerations and Velocities is for the 2nd order coordinated motion trajectory planner.  The other is the Jerk, Acceleration, and Velocity parameters used within KFLOP for independent 3rd order motions.  These are really two different things and it really is best to keep them separate.
> > >  
> > > A lot of the things we are doing really are complicated so the concept of things should be as simple as possible but no simpler often comes into play.  The tendency for everyone is to just expect things to be numb-nuts simple and be frustrated when they aren't is common.  But certainly much could be improved so suggestions are appreciated especially if they are specific.
> > >  
> > > Thanks
> > > TK
> > >  
> > >  
> > >  
> > >
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Sunday, January 29, 2012 1:02 PM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > Brad,
> > >
> > > Probably D) All of the above. I must admit, this has been a very frustrating experience at times. But I certainly don't mean to complain, and I apologize if I've come across that way. It's probably just my frustration and exhaustion coming out in the very imperfect communications means of e-mail. I think dotNet is a wonderful thing, and there's no other way I'd be able to build my own CNC controller app without it. And I know once I get the last few kinks out, this thing is going to make running my machine much more enjoyable.
> > >
> > > I am not a professional software developer, and this is my first serious foray into Windows app development, c#, .NET and many other things. I am rather overwhelmed, not only by all the totally unrelated "real" work I have to get done every day, but by how much information I've had to absorb to make it this far with my app. I am, quite frankly, in information overload. You and Tom are FAR deeper into it than I am, and far, far, FAR more experienced at software development than me, so things that are obvious to you, are not always to me. Looking at the existing code does not always lead me to an answer, especially when it means digging into the bowels of the interpreter or KMotionCNC. Then I run face-first into something like the current problem where writing a single, specific Persist Var crashes the whole system, and I'm dead in the water, because I don't have the means to dig into it any further and figure out what's really going on there.
> > >
> > > My app is now so close to working, I can taste it, but it's been stuck at that point for the last week or more. It's close, but not quite close enough. I'm just groping around in the dark, trying to figure how this all works, and understand enough to do what I need to do, often with very little information to go on. And some of what I do have is confusing/conflicting.
> > >
> > > I suppose my question was mostly about the long-term philosophy of dotNet. The DLL APIs obviously work just fine, but there are quite a few operations that are not at all obvious, until you find the right piece of magic code to make it work. One example is FeedHold. There's no way anyone could look at the APIs and know how to implement that, even though it's a few simple lines of code. It seems to me there is an opportunity to make it easier for us numb-nuts to understand and work with by doing somewhat more than just a literal translation of the underlying DLL APIs. I'm curious if you will take it in that direction.
> > >
> > > As a numb-nuts user, I can tell you what's there can be very confusing, and, to me, seemingly illogical in places. For example, the fact that we have to specify axis parameters in at least three different places. And there are several places with methods or properties called "Halt", or something similar. I am clueless as to how to use these, and how they all interact, if at all. I find myself sifting through the various layers and objects trying to find something that sounds like what I need, and sometimes when I do find it, I wonder "Why is it there?". I'm certain there's always a good reason for it, but I can't always see it. Then when I need it again in the future, I have to go through the whole process again. What I'm trying to do in my "gasket" is provide simple, high-level APIs to the app, so it need not know or care HOW things work, they just do. So, you call a method named "DoThis", and it does this, leaving the GUI to be just a GUI. Seems to me
> > > dotNet, would really benefit from something like that, to make the whole system much more "approachable" to more casual users, and hide the not inconsiderable complexities of the DLL APIs from the user. Any plans to take it more that direction?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > >
> > > > To each their own... but I did not write any gatherHex methods.
> > > >
> > > >
> > > > Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Tom,
> > > > > > > >
> > > > > > > > Did not know that was required.... I'll give it a try.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Ray,
> > > > > > > > >  
> > > > > > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > > > > > >  
> > > > > > > > > Regards
> > > > > > > > > TK
> > > > > > > > >
> > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >  
> > > > > > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > > > > > >
> > > > > > > > > > main()
> > > > > > > > > > {
> > > > > > > > > > KM_Controller KM = new KM_Controller();
> > > > > > > > > > Thread.Sleep(1000);
> > > > > > > > > > GatherHex(0, 8);
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Brad/Tom,
> > > > > > > > > > >
> > > > > > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > > > > > >
> > > > > > > > > > > Here's the code on my side:
> > > > > > > > > > >
> > > > > > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > > > > > {
> > > > > > > > > > > String[] ret = new String[words];
> > > > > > > > > > > int lines = (words + 7) / 8;
> > > > > > > > > > > String[] s = new String[lines];
> > > > > > > > > > >
> > > > > > > > > > > WaitToken();
> > > > > > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > > > > > ReleaseToken();
> > > > > > > > > > > int thisword = 0;
> > > > > > > > > > > foreach (String t in s)
> > > > > > > > > > > {
> > > > > > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > > > > > {
> > > > > > > > > > > ret[thisword] = u;
> > > > > > > > > > > if (++thisword == words)
> > > > > > > > > > > break;
> > > > > > > > > > > }
> > > > > > > > > > > }
> > > > > > > > > > > return ret;
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > > > > > >
> > > > > > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > > > > > >
> > > > > > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > > > > > >
> > > > > > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > > > > > >
> > > > > > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Tom,
> > > > > > > > > > > > >
> > > > > > > > > > > > > OK, not using that.
> > > > > > > > > > > > >
> > > > > > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > TK
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Yes.ÃÆ'Æ'‚ÃÆ'‚  Everything.ÃÆ'Æ'‚ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'Æ'‚ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed
> > > reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the Token prevents this as well.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But I can't see where anything would block while just trying to render the
> > > screen.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  But even that should all be cached so I can't imagine why the screen couldn't
> > > > > > > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On
> > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > > > > > > contains the UI status, then tossing that over to the UI thread to update
> > > > > > > > > > > > > > > > > > > > > > > > > the controls. But, the UI thread also needs to access dotNet when things
> > > > > > > > > > > > > > > > > > > > > > > > > like button events occur. Should I push ALL dotNet accesses to the UI
> > > > > > > > > > > > > > > > > > > > > > > > > thread? Or is there a better way?
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Right now, something I've done has made the hangs much worse. I'm getting
> > > > > > > > > > > > > > > > > > > > > > > > > pretty regular hangs in the DLL, without disconnects, and also can't seem
> > > > > > > > > > > > > > > > > > > > > > > > to
> > > > > > > > > > > > > > > > > > > > > > > > > get the BackgroundWorker thread to exit. It stops updating the display,
> > > > > > > > > > > > > > > > > > > > > > > > but
> > > > > > > > > > > > > > > > > > > > > > > > > doesn't exit.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Well, I moved the display updates to a BackgroundWorker thread by
> > > > > > > > > > > > > > > > > > > > > > > > > plagiarizing what you do in your HTML app. It was relatively painless,
> > > > > > > > > > > > > > > > > > > > > > > > but,
> > > > > > > > > > > > > > > > > > > > > > > > > surprisingly, didn't really make any perceptible difference in terms of
> > > > > > > > > > > > > > > > > > > > > > > > > display update performance. It also, not surprisingly, introduced a couple
> > > > > > > > > > > > > > > > > > > > > > > > > of minor bugs. I have yet to get it to reliably close cleanly. On the
> > > > > > > > > > > > > > > > > > > > > > > > > FormClosing event, I do a CancelAsync, followed by a Sleep(250), but I
> > > > > > > > > > > > > > > > > > > > > > > > still
> > > > > > > > > > > > > > > > > > > > > > > > > sometimes get a null reference error in UpdateDocument when Dispose is
> > > > > > > > > > > > > > > > > > > > > > > > > called. Not sure I understand why that's happening.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > The only thing I will add at this point is try it and you will see.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > I will add that MM uses a multi-threading model, has a lot more
> > > > > > > > > > > > > > > > > > > > > > > > > rendering
> > > > > > > > > > > > > > > > > > > > > > > > > > > going on that a winforms app, also does openGL toolpath display and I
> > > > > > > > > > > > > > > > > > > > > > > > > can
> > > > > > > > > > > > > > > > > > > > > > > > > > > see out to 4-5 decimals changing smoothly during feed moves.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Nowadays any non-trivial app requires multi-threading.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > -Brad
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Wednesday, January 25, 2012 8:59 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Here's where I keep getting stuck - I believe the bulk of the display
> > > > > > > > > > > > > > > > > > > > > > > > > update
> > > > > > > > > > > > > > > > > > > > > > > > > > > time is getting the information from dotNet, not actually updating the
> > > > > > > > > > > > > > > > > > > > > > > > > > > controls. I already update the DROs more often than the other
> > > > > > > > > > > > > > > > > > > > > > > > controls,
> > > > > > > > > > > > > > > > > > > > > > > > > by
> > > > > > > > > > > > > > > > > > > > > > > > > > > just doing the DROs on every timer tick, and the others on alternate
> > > > > > > > > > > > > > > > > > > > > > > > > ticks.
> > > > > > > > > > > > > > > > > > > > > > > > > > > How will another thread improve performance, if the bottleneck is
> > > > > > > > > > > > > > > > > > > > > > > > > getting
> > > > > > > > > > > > > > > > > > > > > > > > > > > the update data (which comes primarily from MainStatus), particularly
> > > > > > > > > > > > > > > > > > > > > > > > > since
> > > > > > > > > > > > > > > > > > > > > > > > > > > I have to go through an invoke to modify each control?
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > First off, you never want to have too many threads running,
> > > > > > > > > > > > > > > > > > > > > > > > > technically
> > > > > > > > > > > > > > > > > > > > > > > > > > > you
> > > > > > > > > > > > > > > > > > > > > > > > > > > > can only have one run per core and anything after that is going to
> > > > > > > > > > > > > > > > > > > > > > > > be
> > > > > > > > > > > > > > > > > > > > > > > > > time
> > > > > > > > > > > > > > > > > > > > > > > > > > > > slicing.
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > If I was making a small lightweight winforms app in .net3.5(like the
> > > > > > > > > > > > > > > > > > > > > > > > > HTML
> > > > > > > > > > > > > > > > > > > > > > > > > > > > controller ;-) ), I would/am use/ing the invoke methods I outlined
> > > > > > > > > > > > > > > > > > > > > > > > > > > earlier.
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > Inside of it, I basically have an endless loop running on a separate
> > > > > > > > > > > > > > > > > > > > > > > > > > > > worker thread using the simple BackgroundWorker class. The endless
> > > > > > > > > > > > > > > > > > > > > > > > > loop
> > > > > > > > > > > > > > > > > > > > > > > > > > > > sleeps every 100ms and I have the DRO's updating on that time slice.
> > > > > > > > > > > > > > > > > > > > > > > > > > > Within
> > > > > > > > > > > > > > > > > > > > > > > > > > > > the loop I also have a counter that I increment/reset every 5 cycles
> > > > > > > > > > > > > > > > > > > > > > > > > and
> > > > > > > > > > > > > > > > > > > > > > > > > > > > when that happens I update the less important items.
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > ><br/><br/>(Message over 64 KB, truncated)
Group: DynoMotion Message: 3573 From: Brad Murry Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...

Hello Ray,

 

Do you have a running list of unresolved issues you are working with/around?

 

-Brad Murry

 

From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
Sent: Sunday, January 29, 2012 5:57 PM
To: DynoMotion@yahoogroups.com
Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...

 

 

Brad,

"I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally." - Who am I to complain! :-)

I'm more than happy to move to a different venue, or method of communication, if it'll make it easier to track things. I'm really not a fan of the Yahoo forums - like you said, it's impossible to track information here. Finding a post you KNOW you read a week ago can take forever.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@...> wrote:
>
> Hello Ray,
>
> I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally.
>
> I also second Tom's statement that all of your efforts are greatly appreciated. I plan to use the .net wrappers for my own projects soon so working with you and others to squash the bugs early on is a huge benefit and I am quite grateful. I tend to agree with you that there are some areas that the API's(c++ as well as .net) can be much improved, unified and simplified. The .net API is relatively new and unproven, so my primary goal is get things working reliably as they are for now. Once things are stable we can add some syntactic sugar.
>
> I'm not here to tell anyone how to act, but it would be more productive if you could also summarize what you are after in your post so I can help you and others(including myself) to make the API better.
>
> For example, I am trying to put a list of bug fixes and feature requests together and it is a bit difficult to sift through the group posts to form a concise plan. Maybe what we really need is an area for bug reports and feature requests…..
>
> At any rate, keep the feedback coming- however colorful you would like to make it and help me out by dumbing down what you are after so I can help.
>
> -Brad Murry
>
>
> --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> >
> > Tom,
> >
> > Thanks. I really do appreciate all the help you and Brad have provided. I'm sorry if my frustration shows at time. I'm sure you'll both be glad when I'm done, and I quit pestering you both! :-)
> >
> > As for axis parameters, right now we need to put them into the Init.c, and, in dotNet, they get written to both CoordMotion and Interpreter. Now, perhaps it's not *necessary* to do that, but that's what the code I copied does (from your example), and I don't understand it enough to modify it. I can post what I've got, if you want to look at it. There are also several other parameters that I have no clue what they are, or what to set them to that I'll need to ask about soon.
> >
> > I think what I'm going to do is put all the config information in one place - a config file managed by the app - then download it to the DSP from there on init.
> >
> > I was not aware I could step through the DLLs. It doesn't work with the current configuration, but I'll try what you suggested, and see if I can get to the bottom of the crashes. Though, unfortunately, the current problem in clearing the PC_COMM command word seems to have a side-effect that causes the crash to occur sometime later, which could be a bugger to find. I have figured out one small piece - the screenful of error dialogs I get is coming out of my re-init code, which says the board is say it's connected, but I get an error when I try to compile and load my init.c. Since the board and/or DLL seems to be hosed at that point (I have to power cycle the board to get things working again - just killing and re-starting the app won't do it), that makes sense.
> >
> > As for simplicity, I understand there is a lot of complexity in there, but what I'm suggesting is a few additional APIs that I suspect would make life easier for 95% of potential users. And, perhaps, just making common operations more obvious. Right now, you've exposed "Expert Mode". Even some more basic, clearly documented examples would make proper usage much easier to understand. I would be happy to volunteer my app for the purpose, and/or my "gasket" layer as a starting point. As I said, the point of the gasket layer is to provide the bulk of the functionality required for a CNC app, like KMotionCNC, with mostly only the GUI elements missing. I'd even be willing to document the hell out of them, so other idiots like me could easily understand how to modify them. It is all dead-simple code (otherwise, I'd never remember how it works....). Though I suspect you'd both run out of the room screaming if you saw some of my code, at least in its current state.... :-)
> >
> > Regards,
> > Ray L.
> >
> > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > >
> > > Hi Ray,
> > >  
> > > Just wanted to point out how much I personally appreciate the effort, work, feedback, persistence, and patience you have even though you are a bit overly candid at times :}
> > >  
> > > I'm not sure you are aware, but when you do come across a function that crashes or fails it is possible to step right into it and enter the C++ libraries all the way to the bottom to see what is wrong. I find it very instructional as well.  Sometimes you need to turn on the "debug unmanaged code" option and target things to the debug directory but I find it well worth the trouble.
> > >  
> > > Regarding the axis parameters in 3 places that you've mentioned several times, where is that?  I think it might be two places.  One set of motion profile parameters of Accelerations and Velocities is for the 2nd order coordinated motion trajectory planner.  The other is the Jerk, Acceleration, and Velocity parameters used within KFLOP for independent 3rd order motions.  These are really two different things and it really is best to keep them separate.
> > >  
> > > A lot of the things we are doing really are complicated so the concept of things should be as simple as possible but no simpler often comes into play.  The tendency for everyone is to just expect things to be numb-nuts simple and be frustrated when they aren't is common.  But certainly much could be improved so suggestions are appreciated especially if they are specific.
> > >  
> > > Thanks
> > > TK
> > >  
> > >  
> > >  
> > >
> > > From: himykabibble <jagboy@>
> > > To: DynoMotion@yahoogroups.com
> > > Sent: Sunday, January 29, 2012 1:02 PM
> > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > >
> > >
> > >  
> > > Brad,
> > >
> > > Probably D) All of the above. I must admit, this has been a very frustrating experience at times. But I certainly don't mean to complain, and I apologize if I've come across that way. It's probably just my frustration and exhaustion coming out in the very imperfect communications means of e-mail. I think dotNet is a wonderful thing, and there's no other way I'd be able to build my own CNC controller app without it. And I know once I get the last few kinks out, this thing is going to make running my machine much more enjoyable.
> > >
> > > I am not a professional software developer, and this is my first serious foray into Windows app development, c#, .NET and many other things. I am rather overwhelmed, not only by all the totally unrelated "real" work I have to get done every day, but by how much information I've had to absorb to make it this far with my app. I am, quite frankly, in information overload. You and Tom are FAR deeper into it than I am, and far, far, FAR more experienced at software development than me, so things that are obvious to you, are not always to me. Looking at the existing code does not always lead me to an answer, especially when it means digging into the bowels of the interpreter or KMotionCNC. Then I run face-first into something like the current problem where writing a single, specific Persist Var crashes the whole system, and I'm dead in the water, because I don't have the means to dig into it any further and figure out what's really going on there.
> > >
> > > My app is now so close to working, I can taste it, but it's been stuck at that point for the last week or more. It's close, but not quite close enough. I'm just groping around in the dark, trying to figure how this all works, and understand enough to do what I need to do, often with very little information to go on. And some of what I do have is confusing/conflicting.
> > >
> > > I suppose my question was mostly about the long-term philosophy of dotNet. The DLL APIs obviously work just fine, but there are quite a few operations that are not at all obvious, until you find the right piece of magic code to make it work. One example is FeedHold. There's no way anyone could look at the APIs and know how to implement that, even though it's a few simple lines of code. It seems to me there is an opportunity to make it easier for us numb-nuts to understand and work with by doing somewhat more than just a literal translation of the underlying DLL APIs. I'm curious if you will take it in that direction.
> > >
> > > As a numb-nuts user, I can tell you what's there can be very confusing, and, to me, seemingly illogical in places. For example, the fact that we have to specify axis parameters in at least three different places. And there are several places with methods or properties called "Halt", or something similar. I am clueless as to how to use these, and how they all interact, if at all. I find myself sifting through the various layers and objects trying to find something that sounds like what I need, and sometimes when I do find it, I wonder "Why is it there?". I'm certain there's always a good reason for it, but I can't always see it. Then when I need it again in the future, I have to go through the whole process again. What I'm trying to do in my "gasket" is provide simple, high-level APIs to the app, so it need not know or care HOW things work, they just do. So, you call a method named "DoThis", and it does this, leaving the GUI to be just a GUI. Seems to me
> > > dotNet, would really benefit from something like that, to make the whole system much more "approachable" to more casual users, and hide the not inconsiderable complexities of the DLL APIs from the user. Any plans to take it more that direction?
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > >
> > > > To each their own... but I did not write any gatherHex methods.
> > > >
> > > >
> > > > Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.
> > > >
> > > > -Brad Murry
> > > >
> > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > >
> > > > > Brad,
> > > > >
> > > > > I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
> > > > >
> > > > > Regards,
> > > > > Ray L.
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > Tom,
> > > > > > > >
> > > > > > > > Did not know that was required.... I'll give it a try.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Ray,
> > > > > > > > >  
> > > > > > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > > > > > >  
> > > > > > > > > Regards
> > > > > > > > > TK
> > > > > > > > >
> > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >  
> > > > > > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > >
> > > > > > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > > > > > >
> > > > > > > > > > main()
> > > > > > > > > > {
> > > > > > > > > > KM_Controller KM = new KM_Controller();
> > > > > > > > > > Thread.Sleep(1000);
> > > > > > > > > > GatherHex(0, 8);
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Brad/Tom,
> > > > > > > > > > >
> > > > > > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > > > > > >
> > > > > > > > > > > Here's the code on my side:
> > > > > > > > > > >
> > > > > > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > > > > > {
> > > > > > > > > > > String[] ret = new String[words];
> > > > > > > > > > > int lines = (words + 7) / 8;
> > > > > > > > > > > String[] s = new String[lines];
> > > > > > > > > > >
> > > > > > > > > > > WaitToken();
> > > > > > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > > > > > ReleaseToken();
> > > > > > > > > > > int thisword = 0;
> > > > > > > > > > > foreach (String t in s)
> > > > > > > > > > > {
> > > > > > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > > > > > {
> > > > > > > > > > > ret[thisword] = u;
> > > > > > > > > > > if (++thisword == words)
> > > > > > > > > > > break;
> > > > > > > > > > > }
> > > > > > > > > > > }
> > > > > > > > > > > return ret;
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > > > > > >
> > > > > > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > > > > > >
> > > > > > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > > > > > >
> > > > > > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > > > > > >
> > > > > > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > Tom,
> > > > > > > > > > > > >
> > > > > > > > > > > > > OK, not using that.
> > > > > > > > > > > > >
> > > > > > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > TK
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >  
> > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ÃÆ'‚ 
> > > > > > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Yes.ÃÆ'Æ'‚ÃÆ'‚  Everything.ÃÆ'Æ'‚ÃÆ'‚  There is basically only two ways to get info from KFLOP.ÃÆ'Æ'‚ÃÆ'‚  Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I will try to find time to look at it soon.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com
> > > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com, Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  In this case if a thread or process issued the Command and had not completed
> > > reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ 
> > > > > > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚  If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢ââ

(Message over 64 KB, truncated)
Group: DynoMotion Message: 3576 From: himykabibble Date: 1/29/2012
Subject: Re: Houston, We Have A (Bizarre) Problem...
Brad,

I think the big ones for me right now are:

Getting MainStatus working reliably
Fixing the "off by one" issue in I/Os
I believe there is a problem with AxisEnabled was it? Always returns false?
The KMotion Path issue (which I believe Tom is fixing)

The showstopper for me right now is whatever is causing my PCComm stuff to blow up, but I can't prove that issue is coming from either dotNet or KMotion. Could well be in my code, but I'm having no lucj pinning it down.

Regards,
Ray L.

--- In DynoMotion@yahoogroups.com, Brad Murry <bradodarb@...> wrote:
>
> Hello Ray,
>
>
>
> Do you have a running list of unresolved issues you are working with/around?
>
>
>
> -Brad Murry
>
>
>
> From: DynoMotion@yahoogroups.com [mailto:DynoMotion@yahoogroups.com] On Behalf Of himykabibble
> Sent: Sunday, January 29, 2012 5:57 PM
> To: DynoMotion@yahoogroups.com
> Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
>
>
>
>
>
> Brad,
>
> "I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally." - Who am I to complain! :-)
>
> I'm more than happy to move to a different venue, or method of communication, if it'll make it easier to track things. I'm really not a fan of the Yahoo forums - like you said, it's impossible to track information here. Finding a post you KNOW you read a week ago can take forever.
>
> Regards,
> Ray L.
>
> --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "bradodarb" <bradodarb@> wrote:
> >
> > Hello Ray,
> >
> > I did not mean to sound as harsh as I may have been, it is just my terse nature so please don't take it personally.
> >
> > I also second Tom's statement that all of your efforts are greatly appreciated. I plan to use the .net wrappers for my own projects soon so working with you and others to squash the bugs early on is a huge benefit and I am quite grateful. I tend to agree with you that there are some areas that the API's(c++ as well as .net) can be much improved, unified and simplified. The .net API is relatively new and unproven, so my primary goal is get things working reliably as they are for now. Once things are stable we can add some syntactic sugar.
> >
> > I'm not here to tell anyone how to act, but it would be more productive if you could also summarize what you are after in your post so I can help you and others(including myself) to make the API better.
> >
> > For example, I am trying to put a list of bug fixes and feature requests together and it is a bit difficult to sift through the group posts to form a concise plan. Maybe what we really need is an area for bug reports and feature requests…..
> >
> > At any rate, keep the feedback coming- however colorful you would like to make it and help me out by dumbing down what you are after so I can help.
> >
> > -Brad Murry
> >
> >
> > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > >
> > > Tom,
> > >
> > > Thanks. I really do appreciate all the help you and Brad have provided. I'm sorry if my frustration shows at time. I'm sure you'll both be glad when I'm done, and I quit pestering you both! :-)
> > >
> > > As for axis parameters, right now we need to put them into the Init.c, and, in dotNet, they get written to both CoordMotion and Interpreter. Now, perhaps it's not *necessary* to do that, but that's what the code I copied does (from your example), and I don't understand it enough to modify it. I can post what I've got, if you want to look at it. There are also several other parameters that I have no clue what they are, or what to set them to that I'll need to ask about soon.
> > >
> > > I think what I'm going to do is put all the config information in one place - a config file managed by the app - then download it to the DSP from there on init.
> > >
> > > I was not aware I could step through the DLLs. It doesn't work with the current configuration, but I'll try what you suggested, and see if I can get to the bottom of the crashes. Though, unfortunately, the current problem in clearing the PC_COMM command word seems to have a side-effect that causes the crash to occur sometime later, which could be a bugger to find. I have figured out one small piece - the screenful of error dialogs I get is coming out of my re-init code, which says the board is say it's connected, but I get an error when I try to compile and load my init.c. Since the board and/or DLL seems to be hosed at that point (I have to power cycle the board to get things working again - just killing and re-starting the app won't do it), that makes sense.
> > >
> > > As for simplicity, I understand there is a lot of complexity in there, but what I'm suggesting is a few additional APIs that I suspect would make life easier for 95% of potential users. And, perhaps, just making common operations more obvious. Right now, you've exposed "Expert Mode". Even some more basic, clearly documented examples would make proper usage much easier to understand. I would be happy to volunteer my app for the purpose, and/or my "gasket" layer as a starting point. As I said, the point of the gasket layer is to provide the bulk of the functionality required for a CNC app, like KMotionCNC, with mostly only the GUI elements missing. I'd even be willing to document the hell out of them, so other idiots like me could easily understand how to modify them. It is all dead-simple code (otherwise, I'd never remember how it works....). Though I suspect you'd both run out of the room screaming if you saw some of my code, at least in its current state.... :-)
> > >
> > > Regards,
> > > Ray L.
> > >
> > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > >
> > > > Hi Ray,
> > > > Â
> > > > Just wanted to point out how much I personally appreciate the effort, work, feedback, persistence, and patience you have even though you are a bit overly candid at times :}
> > > > Â
> > > > I'm not sure you are aware, but when you do come across a function that crashes or fails it is possible to step right into it and enter the C++ libraries all the way to the bottom to see what is wrong. I find it very instructional as well. Sometimes you need to turn on the "debug unmanaged code" option and target things to the debug directory but I find it well worth the trouble.
> > > > Â
> > > > Regarding the axis parameters in 3 places that you've mentioned several times, where is that? I think it might be two places. One set of motion profile parameters of Accelerations and Velocities is for the 2nd order coordinated motion trajectory planner. The other is the Jerk, Acceleration, and Velocity parameters used within KFLOP for independent 3rd order motions. These are really two different things and it really is best to keep them separate.
> > > > Â
> > > > A lot of the things we are doing really are complicated so the concept of things should be as simple as possible but no simpler often comes into play. The tendency for everyone is to just expect things to be numb-nuts simple and be frustrated when they aren't is common. But certainly much could be improved so suggestions are appreciated especially if they are specific.
> > > > Â
> > > > Thanks
> > > > TK
> > > > Â
> > > > Â
> > > > Â
> > > >
> > > > From: himykabibble <jagboy@>
> > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > Sent: Sunday, January 29, 2012 1:02 PM
> > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > >
> > > >
> > > > Â
> > > > Brad,
> > > >
> > > > Probably D) All of the above. I must admit, this has been a very frustrating experience at times. But I certainly don't mean to complain, and I apologize if I've come across that way. It's probably just my frustration and exhaustion coming out in the very imperfect communications means of e-mail. I think dotNet is a wonderful thing, and there's no other way I'd be able to build my own CNC controller app without it. And I know once I get the last few kinks out, this thing is going to make running my machine much more enjoyable.
> > > >
> > > > I am not a professional software developer, and this is my first serious foray into Windows app development, c#, .NET and many other things. I am rather overwhelmed, not only by all the totally unrelated "real" work I have to get done every day, but by how much information I've had to absorb to make it this far with my app. I am, quite frankly, in information overload. You and Tom are FAR deeper into it than I am, and far, far, FAR more experienced at software development than me, so things that are obvious to you, are not always to me. Looking at the existing code does not always lead me to an answer, especially when it means digging into the bowels of the interpreter or KMotionCNC. Then I run face-first into something like the current problem where writing a single, specific Persist Var crashes the whole system, and I'm dead in the water, because I don't have the means to dig into it any further and figure out what's really going on there.
> > > >
> > > > My app is now so close to working, I can taste it, but it's been stuck at that point for the last week or more. It's close, but not quite close enough. I'm just groping around in the dark, trying to figure how this all works, and understand enough to do what I need to do, often with very little information to go on. And some of what I do have is confusing/conflicting.
> > > >
> > > > I suppose my question was mostly about the long-term philosophy of dotNet. The DLL APIs obviously work just fine, but there are quite a few operations that are not at all obvious, until you find the right piece of magic code to make it work. One example is FeedHold. There's no way anyone could look at the APIs and know how to implement that, even though it's a few simple lines of code. It seems to me there is an opportunity to make it easier for us numb-nuts to understand and work with by doing somewhat more than just a literal translation of the underlying DLL APIs. I'm curious if you will take it in that direction.
> > > >
> > > > As a numb-nuts user, I can tell you what's there can be very confusing, and, to me, seemingly illogical in places. For example, the fact that we have to specify axis parameters in at least three different places. And there are several places with methods or properties called "Halt", or something similar. I am clueless as to how to use these, and how they all interact, if at all. I find myself sifting through the various layers and objects trying to find something that sounds like what I need, and sometimes when I do find it, I wonder "Why is it there?". I'm certain there's always a good reason for it, but I can't always see it. Then when I need it again in the future, I have to go through the whole process again. What I'm trying to do in my "gasket" is provide simple, high-level APIs to the app, so it need not know or care HOW things work, they just do. So, you call a method named "DoThis", and it does this, leaving the GUI to be just a GUI. Seems to me
> > > > dotNet, would really benefit from something like that, to make the whole system much more "approachable" to more casual users, and hide the not inconsiderable complexities of the DLL APIs from the user. Any plans to take it more that direction?
> > > >
> > > > Regards,
> > > > Ray L.
> > > >
> > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "bradodarb" <bradodarb@> wrote:
> > > > >
> > > > > To each their own... but I did not write any gatherHex methods.
> > > > >
> > > > >
> > > > > Its also difficult at times to determine whether you are a)requesting a feature b)just complaining or c)misunderstanding something completely and are on your own little process of figuring out.
> > > > >
> > > > > -Brad Murry
> > > > >
> > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > >
> > > > > > Brad,
> > > > > >
> > > > > > I'm kinda wondering why you wrote the GatherHex to take a ref String argument, rather than just a String, and have your APIs deal with the details. That would seem a lot "cleaner" and more user-friendly to me.
> > > > > >
> > > > > > Regards,
> > > > > > Ray L.
> > > > > >
> > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > >
> > > > > > > Geez! Ya know how sometimes you spend too much time on something, and you start seeing what you MEANT to type, rather than what you actually DID type? That's what I did here. Marshalling was the problem, and it's working now. Thanks!
> > > > > > >
> > > > > > > Regards,
> > > > > > > Ray L.
> > > > > > >
> > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > >
> > > > > > > > OK, I did what Brad suggested, initializing the String to new String(' ',255) before the ReadLine call. I am still getting only the first four words back, followed by timeouts for all subsequent lines. So, it made no difference.
> > > > > > > >
> > > > > > > > Regards,
> > > > > > > > Ray L.
> > > > > > > >
> > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > >
> > > > > > > > > Tom,
> > > > > > > > >
> > > > > > > > > Did not know that was required.... I'll give it a try.
> > > > > > > > >
> > > > > > > > > Regards,
> > > > > > > > > Ray L.
> > > > > > > > >
> > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > > > > > >
> > > > > > > > > > Hi Ray,
> > > > > > > > > > ÂÂ
> > > > > > > > > > I didn't see where the string was being "Marshaled" try filling the strings with spaces before the call so the memory gets allocated before making the call and see if that makes it work.
> > > > > > > > > > ÂÂ
> > > > > > > > > > Regards
> > > > > > > > > > TK
> > > > > > > > > >
> > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > Sent: Saturday, January 28, 2012 6:39 PM
> > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > ÂÂ
> > > > > > > > > > It does not like the "ref s[i]" as the first argument to ReadLineTimeout (which I don't understand....), but even passing "ref t", where t is declared as a String, I get only 4 words of Hex data back, and all subsequent reads time out.
> > > > > > > > > >
> > > > > > > > > > Regards,
> > > > > > > > > > Ray L.
> > > > > > > > > >
> > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > Well, this failure is incredibly easy to induce, and 100% repeatable. The below trivial program will throw an "Unable to read or write memory" exception every single time in the first ReadLineTimeout() call in the GatherHex() method. It also leaves a zombie KLfopTest.vshost.exe process that cannot be killed with TaskManager.
> > > > > > > > > > >
> > > > > > > > > > > main()
> > > > > > > > > > > {
> > > > > > > > > > > KM_Controller KM = new KM_Controller();
> > > > > > > > > > > Thread.Sleep(1000);
> > > > > > > > > > > GatherHex(0, 8);
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > Regards,
> > > > > > > > > > > Ray L.
> > > > > > > > > > >
> > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > Brad/Tom,
> > > > > > > > > > > >
> > > > > > > > > > > > I've found another way to induce the fault in dotNet. I'm trying to debug the Gather functions for PC Comm. I do a WriteLine(GetGatherHex, offset, length), followed by one or more ReadLineTimeout(ref String, 500); The call to KM_dotnet_Interop_ReadLineTimeOut is throwing a "Attempted to read or write protected memory" exception every time.
> > > > > > > > > > > >
> > > > > > > > > > > > Here's the code on my side:
> > > > > > > > > > > >
> > > > > > > > > > > > public String[] GatherHex(int offset, int words)
> > > > > > > > > > > > {
> > > > > > > > > > > > String[] ret = new String[words];
> > > > > > > > > > > > int lines = (words + 7) / 8;
> > > > > > > > > > > > String[] s = new String[lines];
> > > > > > > > > > > >
> > > > > > > > > > > > WaitToken();
> > > > > > > > > > > > KMController.WriteLine("GetGatherHex " + offset.ToString("0") + " " + lines.ToString("0"));
> > > > > > > > > > > > for (int i = 0; i < lines; i++)
> > > > > > > > > > > > KMController.ReadLineTimout(ref s[i], 500);
> > > > > > > > > > > > ReleaseToken();
> > > > > > > > > > > > int thisword = 0;
> > > > > > > > > > > > foreach (String t in s)
> > > > > > > > > > > > {
> > > > > > > > > > > > foreach(String u in t.Split(new char[] { ' ', '\n', '\t' }, 8))
> > > > > > > > > > > > {
> > > > > > > > > > > > ret[thisword] = u;
> > > > > > > > > > > > if (++thisword == words)
> > > > > > > > > > > > break;
> > > > > > > > > > > > }
> > > > > > > > > > > > }
> > > > > > > > > > > > return ret;
> > > > > > > > > > > > }
> > > > > > > > > > > >
> > > > > > > > > > > >
> > > > > > > > > > > > Regards,
> > > > > > > > > > > > Ray L.
> > > > > > > > > > > >
> > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > The changes yesterday and early this AM have definitely made a profound difference in the reliability of the system. The connection reliability has been quite good, and I have not seen the kind of hangs I was plagued with before yesterday. In fact, it just got done running a program that took over an hour, and it ran without a hitch, with the toolpath window up the whole time, and me doing other work on the computer at the same time!
> > > > > > > > > > > > >
> > > > > > > > > > > > > I am still seeing occasional odd behaviors, but nothing terrible. The most common thing is the interpreter appears to hang occasionally, but it may well be something happening in the UI as well. It's a relatively rare occurrence in any case. Next time it happens I'll try to figure out where it's stuck.
> > > > > > > > > > > > >
> > > > > > > > > > > > > The axis display update is still slower than I'd like, even after doing everything I could to optimize my end of it. Hopefully getting the MainStatus issues taken care of will improve that.
> > > > > > > > > > > > >
> > > > > > > > > > > > > I have built in a quick and dirty tool table editor that will read and write EMC tool tables, so I now finally have everything I need to be able to take it out to the shop and try to "use it in anger" for the first time!
> > > > > > > > > > > > >
> > > > > > > > > > > > > Next big thing to tackle is implementing all the PC communications, which should be pretty easy - just porting the existing C++ code from KMotionCNC.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > >
> > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > OK, not using that.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > I am still seeing a hang, of sorts. It happens only when my app starts up. I often (50% of the time, if not more) don't see Connected go true when my app starts. If I unplug and re-plug the cable, it comes up every time, and works fine after that.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > That is something relatively new and can only be set via C code as shown below:
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > double Tau = 0.001; // seconds for Low Pass Filter Time Constant
> > > > > > > > > > > > > > > KLP = exp(-TIMEBASE/Tau);
> > > > > > > > > > > > > > > printf("Tau=%f KLP=%f\n",Tau,KLP);
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > It is described in the latter half of this document
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > http://www.dynomotion.com/Help/KMotionCNC/TrajectoryPlanner.htm
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > The default value of KLP is zero which is what is needed to eliminate any smoothing.
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 12:22 PM
> > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Given that I don't even know what that is..... I'd have to say I have no idea. How would that be enabled? I looked through the config settings I'm using (mostly copied from your example code), and don't see anything like that.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > Are you using the KLP low pass coordinated motion smoothing?
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 11:51 AM
> > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > I've played with this quite a bit now, and, overall, things seem to be working reasonably well. Certainly MUCH improved over what I had yesterday in terms of robustness. I have the weird interaction with KMotion (which seems harmless to my app...), the Exception on exit (due to the BackgroundWorker thread refusing to terminate), and the (seemingly random) CoordMotion underflows. Everything else seems to be working fairly nicely now.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > I do notice one odd thing - when I do Stepping, it does not always seem to stop where the line just executed would suggest it should. In some cases, it stops well short of the final position on the line just executed. I understand it might be a step off, but this is much more than that. For example, in the first few lines of DynoMotionBig.ngc, the X position is X-91.234, but after stepping over that line, the X axis is at -91.2554. That's off by almost 0.001", on a machine with a step size of 0.00005". I am updating the DROs from Interpreter.ReadCurMachinePosition(). This is the position in Ch0->Dest as well. Why is it not -91.2340 as it seem to me it should be?
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > Yes.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ Everything.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ There is basically only two ways to get info from KFLOP.ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ Most everything in one shot using MainStatus, or everything individually - IO bits, Enables, Positions, Destinations, TheadStatus, Done Status, etc...
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 9:55 AM
> > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Does the same happen with I/Os? That;'s where I'm really seeing a slowdown. The Enable status doesn't seem to hurt me, and I only poll it maybe twice/second anyway.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Hi Ray,
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > I believe when you do something like ask the KM_Axis for the enable status it goes out and requests that status directly from KFLOP which requires a round trip USB transaction.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ So by not using the MainStatus record we have increased the USB traffic by something like 20~100X.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ It should be possible to get that MainStatus function working reliably.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ I will try to find time to look at it soon.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ I'm currently trying to get the Error Callbacks working.
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > Regards
> > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > From: himykabibble <jagboy@>
> > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > Sent: Friday, January 27, 2012 8:54 AM
> > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > OK, MainStatus is no longer used, and it does seem to habev improved things quite a bit. I'm (so far) no longer seeing hangs, and I it seems I can now exit my app without crashing KMotion. The really good news is it appears I can now connect/disconnect as much as I want, and it seems to work quite reliably. So that is huge!
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I'm using KM_IO for getting I/O data, and KM_Axes for getting KM_Axis for getting axis enables. One change for the worse that I do notice: On the buttons with indicator "LEDs", like the spindle and coolant controls, it takes a LONG time from when I press the button (which sets the I/O) for the LED to light (based on reading a true for that bit on KM_IO) - on the order of 1.5 seconds! That is very significantly degraded from when I was using MainStatus.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > One new problem that has crept in:
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > I'm getting fairly frequent coordinated motion buffer underflows. Never seen those before, but that snuck in with the threading changes, not the MainStatus change.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Overall, I'd say this is a big step forward, despite the new problems. Certainly in terms of stability and predictability, it seems considerably improved like this.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Now if I can just figure out how to make the DSP threads end when they should, and figure out how to cleanly kill the damned BackgroundWorker....
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > I'm going to make the change to not use MainStatus - will be quite easy. I'm curious though - I mostly use it for checking state of I/O bits. If I instead use KM_IO, how up-to-date will that be? Do you periodically refresh it? The other thing I use MainStatus for is polling to wait for a thread to complete. Is there an alternative way to do that?
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > I already get the axis positions from the Interpreter. It's not a big deal to get most other things from the KM_IO and other places. I'll give it a shot and let you know. Though the hangs and other weird things I've seen have not been coming from reading MainStatus - they've been in Persist read/writes, Compile and Load, and other places. I do consistently see UpdateStatus slow waaaaaaaay down after a disconnect/reconnect. The test program I posted will reliably induce two different failures - one a hang in WritePersistAsDec, and the other garbatizing the path passed into CompileAndLoadCoff.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "bradodarb" <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Once you pull all those locks out ;).....
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Can you try something else for the sake of argument?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Remove the use of the MainStatus and just get the axis values from the
> > > > > > > > > > > > > > > > > > > > > interpreter and get your IO status from your KM_IO objects.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > I am curious to see if the MainStatus access methods are the problem here and this will assert that theory imperically.
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > Are you game?
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Tom,
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I tend to agree with you about the value of multiple threads.. They're great if you have a time-consuing process and want to keep the UI responsive, but that's not the problem I'm having. And my conversion to a multi-threaded model over the last few hours would seem to confirm what you say, as I'm not really seeing any significanr difference in the screen update rate from what I had with everything in one thread. But, multiple threads can often simplify things for the programmer (while potentially complicating other things...).
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > I am very anxious to get to the bottom of the (now frequent) hangs I'm seeing, so I'm happy we now have very repeatable, high failure rate test cases for you guys to play with. I don't doubt I'm doing some things wrong, but I can't see what I could be doing that would explain the libraries to just hanging, or returning incorrect connection data, both of which really make life very difficult. Hopefully you and Brad will get that sorted in short order, and I can finally start making chips! :-)
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > BTW - Nobody ever answered my question about how the tool file is located. I still can't figure out where the heck it's getting the tool length data it's using....
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Tom Kerekes <tk@> wrote:
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Hi Guys,
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > I think it is important to get to the bottom of the update performance, its great that it is being looked at in detail.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ And I'm curious to learn how .NET handles things differently than C++ MFC and sor forth.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > Here are just some of my thoughts/comments - feel free to correct me where I'm wrong.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > #1 the KMotion Libraries really don't need any external Locking as they contain Mutexes and should be thread safe already.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ WriteLine and ReadLine and WriteLineReadLine are already guaranteed to be atomic.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ The one exception is a WriteLine which sends a command that will take N ReadLines to get the response.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ In this case if a thread or process issued the Command and had not completed
> > > > reading back all of the response lines, and another thread issed a WriteLineReadLine then the response lines would get mixed up.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ So the WaitToken ReleaseToken can be used to avoid this problem.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > The method all seems to work. You can run multiple instances of KMotion, KMotionCNC, and other Apps some of which have multiple threads accessing the libraries without any conflicts.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > The internal Global/System wide Windows mutex that is used in the Libraries works in a way that everyone gets a turn in a reasonable amount of time.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ If we aren't careful situations can happen where due to coincidence or circumstancesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ one Thread gets completely or nearly completely locked out.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ And in some cases this might even cause a dead lock.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > There is one other thing that is difficult to describe that the Wait/Release Token helps with which is related to how the Windows Message Queue works.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ If the GUI thread is executing in a message event (or Timer) and does something like displays a MessageBox, it is possible for the message event to re-enter which may result in the libraries being re-entered by the same thread.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ So the Token prevents this as well.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > #2 I can't see how multiple threads would help the Screen Update rate in any way.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ Multiple threads only help speed things upÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ when something blocks so that while one thread is blocked another can wake up and do useful work.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ But I can't see where anything would block while just trying to render the
> > > > screen.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ The only thing I can think of is if in some convoluted way the disk is required to read a bitmap or XML file or something.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ But even that should all be cached so I can't imagine why the screen couldn't
> > > > > > > > > > be refreshed at 200 frames per second by a single thread.
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > #3 I don't think multiple threads allows you to make use of multiple CPU cores.ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ In MS Windows for two threads to have any chance to execute at the same time they must be in different Window's Processes (Apps).ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ When an App is launched by Windows it is assigned a single CPU core and all threads in that process must run on that core.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Anyway, just some thoughts..
> > > > > > > > > > > > > > > > > > > > > > > Thanks
> > > > > > > > > > > > > > > > > > > > > > > TK
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > ________________________________
> > > > > > > > > > > > > > > > > > > > > > > From: bradodarb <bradodarb@>
> > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:46 PM
> > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚ÂÂ
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > Yes, lock every call.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > MM, being a WPF/MVVM app takes advantage of databinding which auto dispatches things.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > looking forward to hearing back your results.
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , "himykabibble" <jagboy@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Thanks. I'll give that a shot, and report back - shouldn't take too long. I assume I must surround *all* KM accesses with locks for them to be effective?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > "I never ran into it on MM as it never accesses the GUI thread." - How did you avoid it? Am I just doing a lot more display updating with controller data than you are?
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> , Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Ray,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > As far as your code goes, I would be looking with an non-judgmental eye and
> > > > > > > > > > > > > > > > > > > > > > > > > with the only goal of finding your problem.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Before that , you could try to surround any calls to the KM_Controller
> > > > > > > > > > > > > > > > > > > > > > > > > instance with a lock clause. This will allow only one thread at a time to
> > > > > > > > > > > > > > > > > > > > > > > > > access the controller object.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Example::
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > var status = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > var status2 = _Controller.WriteLineReadLine("Version");
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Basically, any function you are using the KM_Controller instance in may need
> > > > > > > > > > > > > > > > > > > > > > > > > to be placed in a lock.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Example2::
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Public void MyUpdatingOrCommandingFunction(argsÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > lock(_Controller)
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > //Do stuff with your controller here
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Try this and let me know if it helps. It is making sense to me that the
> > > > > > > > > > > > > > > > > > > > > > > > > KM_Controller is not Thread safe as it is maintaining pointer referencesÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'â€Â 'ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'‚ÃÆ'‚¢ÃÆ'Æ'Æ'ÃÆ'‚¢ÃÆ'Æ'¢ÃÆ'¢â‚¬Å¡ÃÆ'‚¬ÃÆ'Æ'…ÃÆ'‚¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¬ÃÆ'Æ'Æ'ÃÆ'†'ÃÆ'Æ'¢ÃÆ'¢â€šÂ¬ÃÆ'…¡ÃÆ'Æ'Æ'ÃÆ'¢â‚¬Å¡ÃÆ'Æ'‚ÃÆ'‚¦.
> > > > > > > > > > > > > > > > > > > > > > > > > I never ran into it on MM as it never accesses the GUI thread.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > -Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> ] On
> > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 9:14 PM
> > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I'd be happy to send you my code, if you promise not to laugh too hard....
> > > > > > > > > > > > > > > > > > > > > > > > > But perhaps a simple example:
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > My BackgroundWorker Thread needs to do UpdateStatus, and read things like
> > > > > > > > > > > > > > > > > > > > > > > > > current tool, spindle RPM, and a number of other things. Those are currently
> > > > > > > > > > > > > > > > > > > > > > > > > be done in the BackgroundWorker thread by direct calls to my KM_Controller.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Some of the Button Click handlers also need to access things in
> > > > > > > > > > > > > > > > > > > > > > > > > KM_Controller. For example, the SpindleCW button needs to set two I/Os, and
> > > > > > > > > > > > > > > > > > > > > > > > > run a DSP program to set the PWM. For this, the ButtonClick handler calls a
> > > > > > > > > > > > > > > > > > > > > > > > > method in my dotNet "gasket" that handles all this.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > So, My KM_Controller is currently getting called by both the UI thread, and
> > > > > > > > > > > > > > > > > > > > > > > > > the BackgroundWorker thread, which I assume is not a good idea. Would it not
> > > > > > > > > > > > > > > > > > > > > > > > > be better to have only one thread talking the KM_Controller? If so, should I
> > > > > > > > > > > > > > > > > > > > > > > > > move all calls from the BackgroundWorker thread to the UI thread, or
> > > > > > > > > > > > > > > > > > > > > > > > > vice-versa. Or perhaps there's another/better option?
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > I looked through your HTML app code, but you don't seem to be dealing with
> > > > > > > > > > > > > > > > > > > > > > > > > that problem yet, since it appears to me only the DROs are actually
> > > > > > > > > > > > > > > > > > > > > > > > > functional, and their operation is straight-forward (though I note you are
> > > > > > > > > > > > > > > > > > > > > > > > > making calls directly to dotrNet from the BackgroundWorker DoWork method).
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > > > > > > > > > > > > > Ray L.
> > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > --- In DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ,
> > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry <bradodarb@> wrote:
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Hello Ray,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I would probably need to see some code to be much help.
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad Murry
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > From: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > [mailto:DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com> ]
> > > > > > > > > > > > > > > > > > > > > > > > > On
> > > > > > > > > > > > > > > > > > > > > > > > > > Behalf Of himykabibble
> > > > > > > > > > > > > > > > > > > > > > > > > > Sent: Thursday, January 26, 2012 8:57 PM
> > > > > > > > > > > > > > > > > > > > > > > > > > To: DynoMotion@yahoogroups.com <mailto:DynoMotion%40yahoogroups.com> <mailto:DynoMotion%40yahoogroups.com>
> > > > > > > > > > > > > > > > > > > > > > > > > > Subject: [DynoMotion] Re: Houston, We Have A (Bizarre) Problem...
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > Brad,
> > > > > > > > > > > > > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > > > > > > > > > > > > I've got this working pretty well now, with a few exceptions. But I'm not
> > > > > > > > > > > > > > > > > > > > > > > > > > clear on the right way to handle communications with dotNet. My UI update
> > > > > > > > > > > > > > > > > > > > > > > > > > thread needs to access various dotNet data to create the updates. Right
> > > > > > > > > > > > > > > > > > > > > > > > > now,
> > > > > > > > > > > > > > > > > > > > > > > > > > I'm doing those accesses in the DoWork method, creating an object that
> > > > > > > > > > > > > > > > > > > > > > > > > > contains the UI status, th<br/><br/>(Message over 64 KB, truncated)